示例#1
0
 def test_dir_ensure_raises_exception_on_failure(self, *args, **kwargs):
     with self.assertRaises(SystemExit) as cm:
         os_helpers.dir_ensure(location='/tmp/no-valid-path',
                               mode='755',
                               owner='not-a-valid-user',
                               group='not-a-valid-group',
                               recursive=True,
                               use_sudo=False)
     self.assertEqual(cm.exception.code, 1)
示例#2
0
 def test_dir_ensure_raises_exception_on_failure(self, *args, **kwargs):
     with self.assertRaises(SystemExit) as cm:
         os_helpers.dir_ensure(location='/tmp/no-valid-path',
                                        mode='755',
                                        owner='not-a-valid-user',
                                        group='not-a-valid-group',
                                        recursive=True,
                                        use_sudo=False)
     self.assertEqual(cm.exception.code, 1)
示例#3
0
 def test_dir_ensure_creates_dir_if_missing_as_root(self, *args, **kwargs):
     # make sure we have a user1 and group1 on our docker instance
     sudo('/usr/sbin/useradd user1')
     sudo('/usr/sbin/groupadd group1')
     os_helpers.dir_ensure(location='/tmp/temp1',
                           mode='755',
                           owner='user1',
                           group='group1',
                           recursive=False,
                           use_sudo=True)
     self.assertTrue(sudo('ls -d /tmp/temp1'))
示例#4
0
 def test_dir_ensure_creates_dir_recursive_if_missing(self, *args, **kwargs):
     # make sure we have a user1 and group1 on our docker instance
     sudo('/usr/sbin/useradd user1')
     sudo('/usr/sbin/groupadd group1')
     os_helpers.dir_ensure(location='/tmp/level1/level2',
                                    mode='755',
                                    owner='user1',
                                    group='group1',
                                    recursive=True,
                                    use_sudo=False)
     self.assertTrue(sudo('ls -d /tmp/level1/level2'))
示例#5
0
    def test_dir_ensure_without_sudo_updates_perms(self, *args, **kwargs):
        # make sure we have a user1 and group1 on our docker instance
        sudo('/usr/sbin/useradd user1')
        sudo('/usr/sbin/groupadd group1')

        os_helpers.dir_ensure(location='/tmp/temp1',
                              mode='700',
                              owner='user1',
                              group='group1',
                              recursive=False,
                              use_sudo=False)

        perms, x, owner, group = sudo('ls -ld /tmp/temp1').split(' ')[0:4]
        self.assertEquals(perms, 'drwx------')
        self.assertEquals(owner, 'user1')
        self.assertEquals(group, 'group1')
示例#6
0
    def test_dir_ensure_without_sudo_updates_perms(self, *args, **kwargs):
        # make sure we have a user1 and group1 on our docker instance
        sudo('/usr/sbin/useradd user1')
        sudo('/usr/sbin/groupadd group1')

        os_helpers.dir_ensure(location='/tmp/temp1',
                                       mode='700',
                                       owner='user1',
                                       group='group1',
                                       recursive=False,
                                       use_sudo=False)

        perms, x, owner, group = sudo('ls -ld /tmp/temp1').split(' ')[0:4]
        self.assertEquals(perms, 'drwx------')
        self.assertEquals(owner, 'user1')
        self.assertEquals(group, 'group1')
示例#7
0
    def test_dir_ensure_with_sudo_updates_perms_recursively(
            self, *args, **kwargs):
        # make sure we have a user1 and group1 on our docker instance
        sudo('/usr/sbin/useradd user1')
        sudo('/usr/sbin/groupadd group1')
        sudo('mkdir /tmp/level1')
        sudo('mkdir /tmp/level1/level2')

        os_helpers.dir_ensure(location='/tmp/level1',
                              mode='700',
                              owner='user1',
                              group='group1',
                              recursive=True,
                              use_sudo=True)

        for folder in ['/tmp/level1', '/tmp/level1/level2']:
            perms, x, owner, group = sudo('ls -ld %s' % folder).split(' ')[0:4]
            self.assertEquals(perms, 'drwx------')
            self.assertEquals(owner, 'user1')
            self.assertEquals(group, 'group1')
示例#8
0
    def test_dir_ensure_with_sudo_updates_perms_recursively(self,
                                                            *args,
                                                            **kwargs):
        # make sure we have a user1 and group1 on our docker instance
        sudo('/usr/sbin/useradd user1')
        sudo('/usr/sbin/groupadd group1')
        sudo('mkdir /tmp/level1')
        sudo('mkdir /tmp/level1/level2')

        os_helpers.dir_ensure(location='/tmp/level1',
                                       mode='700',
                                       owner='user1',
                                       group='group1',
                                       recursive=True,
                                       use_sudo=True)

        for folder in ['/tmp/level1', '/tmp/level1/level2']:
            perms, x, owner, group = sudo('ls -ld %s' % folder).split(' ')[0:4]
            self.assertEquals(perms, 'drwx------')
            self.assertEquals(owner, 'user1')
            self.assertEquals(group, 'group1')
示例#9
0
    def test_dir_ensure_returns_True_on_sucess(self, *args, **kwargs):
        # make sure we have a user1 and group1 on our docker instance
        sudo('/usr/sbin/useradd user1')
        sudo('/usr/sbin/groupadd group1')
        sudo('mkdir /tmp/temp1')

        result = os_helpers.dir_ensure(location='/tmp/temp1',
                                       mode='755',
                                       owner='user1',
                                       group='group1',
                                       recursive=True,
                                       use_sudo=True)
        self.assertTrue(result)
示例#10
0
    def test_dir_ensure_returns_True_on_sucess(self, *args, **kwargs):
        # make sure we have a user1 and group1 on our docker instance
        sudo('/usr/sbin/useradd user1')
        sudo('/usr/sbin/groupadd group1')
        sudo('mkdir /tmp/temp1')

        result = os_helpers.dir_ensure(location='/tmp/temp1',
                                       mode='755',
                                       owner='user1',
                                       group='group1',
                                       recursive=True,
                                       use_sudo=True)
        self.assertTrue(result)