[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Wed Dec 12 07:24:03 UTC 2018


The branch, master has been updated
       via  bc179e6b5e7 tests: Add SMB Py binding .deltree test case
       via  31d4f692ad9 s4:libcli: Fix error in smbcli_deltree()
       via  da30c824b82 tests: Extend SMB test_save_load_text case to check overwrite
       via  629a41fc654 tests: Extend SMB Py binding .list() test-case
       via  b84cea18fcc tests: Fix SMB Py binding .unlink() test case assertion
       via  fa77209dea4 tests: Add SMB Py binding .chkpath() test case
       via  35e1a7989d2 autobuild: convert top_commit_msg to str for Py 3
       via  25ab429371f autobuild: py3: cope with bytes when compiling system-info.txt
      from  8d333f43055 third_party/dnspython: Remove dnspython library from third_party

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit bc179e6b5e748042c9c247b1abc1c326e9c61d29
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Thu Dec 6 16:16:36 2018 +1300

    tests: Add SMB Py binding .deltree test case
    
    Add a more thorough test case that .deltree works as expected.
    
    Note that we get a slightly different NT_STATUS error in file_exists()
    if the parent directory doesn't exist, e.g.
    /non-existent-dir/nonexistent.txt
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Wed Dec 12 08:23:07 CET 2018 on sn-devel-144

commit 31d4f692ad94cc5dfb82433cf6e3bd82ff805a4a
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Thu Dec 6 16:03:23 2018 +1300

    s4:libcli: Fix error in smbcli_deltree()
    
    Commit 094afe614b6282 fixed an uninitialized variable, which meant we
    tried to delete the file twice. The 2nd time fails, so the function
    returns an error, instead of success (even though the file is now gone).
    
    Note we want to be using the source3 SMB library code going forward.
    However, fixing this bug makes it easier to write tests against the
    (currently s4) SMB python bindings.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit da30c824b8240e92ad4bcdcd174d56c39235412e
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Wed Dec 5 12:51:22 2018 +1300

    tests: Extend SMB test_save_load_text case to check overwrite
    
    Extend the test case to check overwriting a file as well. Currently this
    has the behaviour of appending to the existing file, rather than
    overwriting the file with new contents.
    
    It's not clear from the API that this is the intended behaviour in this
    case, so I've marked it as a failure.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 629a41fc6542cda9c2d60f99e8d7856aa1e081e5
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Mon Dec 3 17:22:43 2018 +1300

    tests: Extend SMB Py binding .list() test-case
    
    Extend the tests to better reflect some of the .list() functionality we
    expect.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit b84cea18fcc54f599db9580fd027b8d530d6b4bd
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Mon Dec 3 11:15:14 2018 +1300

    tests: Fix SMB Py binding .unlink() test case assertion
    
    The current assertion would never detect if the unlink API is broken.
    The chkpath() API is only useful for checking if directories exist, so
    it will always return False for a regular file (regardless of whether
    the file actually exists or not).
    
    Rework the test case so we assert that the file exists by trying to read
    its contents (which will throw an error if the file doesn't exist).
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit fa77209dea48c623fa3052a65b2d8dad9f146198
Author: Tim Beale <timbeale at catalyst.net.nz>
Date:   Mon Dec 3 11:01:14 2018 +1300

    tests: Add SMB Py binding .chkpath() test case
    
    chkpath was only tested incidentally (and that assertion was wrong). Add
    a proper test to prove it works correctly. We can then clean-up the
    incorrect assertion in the next patch.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676
    
    Signed-off-by: Tim Beale <timbeale at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 35e1a7989d2af4508abe589ca4dcb1e73342b875
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Wed Dec 12 10:20:31 2018 +1300

    autobuild: convert top_commit_msg to str for Py 3
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 25ab429371f7cd4d4cd572d843d3607f2ce1db6f
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Wed Dec 12 10:17:38 2018 +1300

    autobuild: py3: cope with bytes when compiling system-info.txt
    
    The command output looks like b'foo\nbar' in string-space.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 python/samba/tests/smb.py   | 130 ++++++++++++++++++++++++++++++++++++++++++++
 script/autobuild.py         |  12 +++-
 selftest/knownfail.d/smb    |   3 +
 source4/libcli/clideltree.c |   2 +-
 4 files changed, 143 insertions(+), 4 deletions(-)
 create mode 100644 selftest/knownfail.d/smb


Changeset truncated at 500 lines:

diff --git a/python/samba/tests/smb.py b/python/samba/tests/smb.py
index e0e60e37102..68936473d33 100644
--- a/python/samba/tests/smb.py
+++ b/python/samba/tests/smb.py
@@ -20,6 +20,9 @@ import os
 import random
 import sys
 from samba import smb
+from samba import NTSTATUSError
+from samba.ntstatus import (NT_STATUS_OBJECT_NAME_NOT_FOUND,
+                            NT_STATUS_OBJECT_PATH_NOT_FOUND)
 
 PY3 = sys.version_info[0] == 3
 addom = 'addom.samba.example.com/'
@@ -51,20 +54,136 @@ class SMBTests(samba.tests.TestCase):
             pass
 
     def test_list(self):
+        # check a basic listing returns the items we expect
         ls = [f['name'] for f in self.conn.list(addom)]
         self.assertIn('scripts', ls,
                       msg='"scripts" directory not found in sysvol')
         self.assertIn('Policies', ls,
                       msg='"Policies" directory not found in sysvol')
+        self.assertNotIn('..', ls,
+                         msg='Parent (..) found in directory listing')
+        self.assertNotIn('.', ls,
+                         msg='Current dir (.) found in directory listing')
+
+        # using a '*' mask should be the same as using no mask
+        ls_wildcard = [f['name'] for f in self.conn.list(addom, "*")]
+        self.assertEqual(ls, ls_wildcard)
+
+        # applying a mask should only return items that match that mask
+        ls_pol = [f['name'] for f in self.conn.list(addom, "Pol*")]
+        expected = ["Policies"]
+        self.assertEqual(ls_pol, expected)
+
+        # each item in the listing is a has with expected keys
+        expected_keys = ['attrib', 'mtime', 'name', 'short_name', 'size']
+        for item in self.conn.list(addom):
+            for key in expected_keys:
+                self.assertIn(key, item,
+                              msg="Key '%s' not in listing '%s'" % (key, item))
+
+    def test_deltree(self):
+        """The smb.deltree API should delete files and sub-dirs"""
+        # create some test sub-dirs
+        dirpaths = []
+        empty_dirs = []
+        cur_dir = test_dir
+        for subdir in ["subdir-X", "subdir-Y", "subdir-Z"]:
+            path = self.make_sysvol_path(cur_dir, subdir)
+            self.conn.mkdir(path)
+            dirpaths.append(path)
+            cur_dir = path
+
+            # create another empty dir just for kicks
+            path = self.make_sysvol_path(cur_dir, "another")
+            self.conn.mkdir(path)
+            empty_dirs.append(path)
+
+        # create some files in these directories
+        filepaths = []
+        for subdir in dirpaths:
+            for i in range(1, 4):
+                contents = "I'm file {0} in dir {1}!".format(i, subdir)
+                path = self.make_sysvol_path(subdir, "file-{0}.txt".format(i))
+                self.conn.savefile(path, test_contents.encode('utf8'))
+                filepaths.append(path)
+
+        # sanity-check these dirs/files exist
+        for subdir in dirpaths + empty_dirs:
+            self.assertTrue(self.conn.chkpath(subdir),
+                            "Failed to create {0}".format(subdir))
+        for path in filepaths:
+            self.assertTrue(self.file_exists(path),
+                            "Failed to create {0}".format(path))
+
+        # try using deltree to remove a single empty directory
+        path = empty_dirs.pop(0)
+        self.conn.deltree(path)
+        self.assertFalse(self.conn.chkpath(path),
+                         "Failed to delete {0}".format(path))
+
+        # try using deltree to remove a single file
+        path = filepaths.pop(0)
+        self.conn.deltree(path)
+        self.assertFalse(self.file_exists(path),
+                         "Failed to delete {0}".format(path))
+
+        # delete the top-level dir
+        self.conn.deltree(test_dir)
+
+        # now check that all the dirs/files are no longer there
+        for subdir in dirpaths + empty_dirs:
+            self.assertFalse(self.conn.chkpath(subdir),
+                             "Failed to delete {0}".format(subdir))
+        for path in filepaths:
+            self.assertFalse(self.file_exists(path),
+                             "Failed to delete {0}".format(path))
+
+    def file_exists(self, filepath):
+        """Returns whether a regular file exists (by trying to open it)"""
+        try:
+            self.conn.loadfile(filepath)
+            exists = True;
+        except NTSTATUSError as err:
+            if (err.args[0] == NT_STATUS_OBJECT_NAME_NOT_FOUND or
+                err.args[0] == NT_STATUS_OBJECT_PATH_NOT_FOUND):
+                exists = False
+            else:
+                raise err
+        return exists
 
     def test_unlink(self):
         """
         The smb.unlink API should delete file
         """
+        # create the test file
+        self.assertFalse(self.file_exists(test_file))
         self.conn.savefile(test_file, binary_contents)
+        self.assertTrue(self.file_exists(test_file))
+
+        # delete it and check that it's gone
         self.conn.unlink(test_file)
+        self.assertFalse(self.file_exists(test_file))
+
+    def test_chkpath(self):
+        """Tests .chkpath determines whether or not a directory exists"""
+
+        self.assertTrue(self.conn.chkpath(test_dir))
+
+        # should return False for a non-existent directory
+        bad_dir = self.make_sysvol_path(test_dir, 'dont_exist')
+        self.assertFalse(self.conn.chkpath(bad_dir))
+
+        # should return False for files (because they're not directories)
+        self.conn.savefile(test_file, binary_contents)
         self.assertFalse(self.conn.chkpath(test_file))
 
+        # check correct result after creating and then deleting a new dir
+        new_dir = self.make_sysvol_path(test_dir, 'test-new')
+        self.conn.mkdir(new_dir)
+        self.assertTrue(self.conn.chkpath(new_dir))
+        self.conn.rmdir(new_dir)
+        self.assertFalse(self.conn.chkpath(new_dir))
+
     def test_save_load_text(self):
 
         self.conn.savefile(test_file, test_contents.encode('utf8'))
@@ -73,6 +192,13 @@ class SMBTests(samba.tests.TestCase):
         self.assertEquals(contents.decode('utf8'), test_contents,
                           msg='contents of test file did not match what was written')
 
+        # check we can overwrite the file with new contents
+        new_contents = 'wxyz' * 128
+        self.conn.savefile(test_file, new_contents.encode('utf8'))
+        contents = self.conn.loadfile(test_file)
+        self.assertEquals(contents.decode('utf8'), new_contents,
+                          msg='contents of test file did not match what was written')
+
     # with python2 this will save/load str type (with embedded nulls)
     # with python3 this will save/load bytes type
     def test_save_load_string_bytes(self):
@@ -99,3 +225,7 @@ class SMBTests(samba.tests.TestCase):
         contents = self.conn.loadfile(test_file)
         self.assertEquals(contents, binary_contents,
                           msg='contents of test file did not match what was written')
+
+    def make_sysvol_path(self, dirpath, filename):
+        # return the dir + filename as a sysvol path
+        return os.path.join(dirpath, filename).replace('/', '\\')
diff --git a/script/autobuild.py b/script/autobuild.py
index c71b85a85b4..2ea9e55b932 100755
--- a/script/autobuild.py
+++ b/script/autobuild.py
@@ -608,10 +608,15 @@ class buildlist(object):
     def write_system_info(self):
         filename = 'system-info.txt'
         f = open(filename, 'w')
-        for cmd in ['uname -a', 'free', 'cat /proc/cpuinfo',
-                    'cc --version', 'df -m .', 'df -m %s' % testbase]:
+        for cmd in ['uname -a',
+                    'free',
+                    'cat /proc/cpuinfo',
+                    'cc --version',
+                    'df -m .',
+                    'df -m %s' % testbase]:
+            out = run_cmd(cmd, output=True, checkfail=False)
             print('### %s' % cmd, file=f)
-            print(run_cmd(cmd, output=True, checkfail=False), file=f)
+            print(out.decode('utf8', 'backslashreplace'), file=f)
             print(file=f)
         f.close()
         return filename
@@ -925,6 +930,7 @@ os.environ['TMPDIR'] = test_tmpdir
 
 # get the top commit message, for emails
 top_commit_msg = run_cmd("git log -1", dir=gitroot, output=True)
+top_commit_msg = top_commit_msg.decode('utf-8', 'backslashreplace')
 
 try:
     os.makedirs(testbase)
diff --git a/selftest/knownfail.d/smb b/selftest/knownfail.d/smb
new file mode 100644
index 00000000000..32989a81374
--- /dev/null
+++ b/selftest/knownfail.d/smb
@@ -0,0 +1,3 @@
+# currently savefile appends rather than overwriting
+samba.tests.smb.samba.tests.smb.SMBTests.test_save_load_text\(ad_dc:local\)
+samba.tests.smb.python2.samba.tests.smb.SMBTests.test_save_load_text\(ad_dc:local\)
diff --git a/source4/libcli/clideltree.c b/source4/libcli/clideltree.c
index 7bce95c2a17..e8007f4495a 100644
--- a/source4/libcli/clideltree.c
+++ b/source4/libcli/clideltree.c
@@ -99,7 +99,7 @@ int smbcli_deltree(struct smbcli_tree *tree, const char *dname)
 
 	/* it might be a file */
 	status = smbcli_unlink(tree, dname);
-	if (NT_STATUS_IS_OK(smbcli_unlink(tree, dname))) {
+	if (NT_STATUS_IS_OK(status)) {
 		return 1;
 	}
 	if (NT_STATUS_EQUAL(smbcli_nt_error(tree), NT_STATUS_OBJECT_NAME_NOT_FOUND) ||


-- 
Samba Shared Repository



More information about the samba-cvs mailing list