コード例 #1
0
    def test_add_user(self):
        """Adds a user to a virtual machine, using the argument parser"""
        # Ensure VM does not exist
        test_vm_object = VirtualMachine.create(
            self.mcvirt,
            self.test_vm['name'],
            self.test_vm['cpu_count'],
            self.test_vm['memory_allocation'],
            self.test_vm['disks'],
            self.test_vm['networks'])
        self.assertTrue(
            VirtualMachine._check_exists(
                self.mcvirt.getLibvirtConnection(),
                self.test_vm['name']))

        # Ensure user is not in 'user' group
        self.assertFalse(
            self.test_user in self.auth_object.get_users_in_permission_group(
                'user',
                test_vm_object))

        # Add user to 'user' group using parser
        self.parser.parse_arguments(
            'permission --add-user %s %s' %
            (self.test_user,
             self.test_vm['name']),
            mcvirt_instance=self.mcvirt)

        # Ensure VM exists
        self.assertTrue(
            self.test_user in self.auth_object.get_users_in_permission_group(
                'user',
                test_vm_object))
コード例 #2
0
    def test_remove_user(self):
        """Removes a user from a virtual machine, using the argument parser"""
        # Ensure VM does not exist
        test_vm_object = VirtualMachine.create(
            self.mcvirt,
            self.test_vm['name'],
            self.test_vm['cpu_count'],
            self.test_vm['memory_allocation'],
            self.test_vm['disks'],
            self.test_vm['networks'])
        self.assertTrue(
            VirtualMachine._check_exists(
                self.mcvirt.getLibvirtConnection(),
                self.test_vm['name']))

        # Add user to 'user' group and ensure they have been added
        self.auth_object.add_user_permission_group(self.mcvirt, 'user', self.test_user,
                                                   test_vm_object)
        self.assertTrue(
            self.test_user in self.auth_object.get_users_in_permission_group(
                'user',
                test_vm_object))

        # Remove user from 'user' group using parser
        self.parser.parse_arguments(
            'permission --delete-user %s %s' %
            (self.test_user,
             self.test_vm['name']),
            mcvirt_instance=self.mcvirt)

        # Ensure user is no longer in 'user' group
        self.assertFalse(
            self.test_user in self.auth_object.get_users_in_permission_group(
                'user',
                test_vm_object
            ))