Esempio n. 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))
Esempio n. 2
0
    def test_attempt_add_superuser_to_vm(self):
        """Attempts to add a user as a superuser to a VM"""
        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']
        )

        with self.assertRaises(MCVirtException):
            self.parser.parse_arguments('permission --add-superuser %s %s' %
                                        (self.test_user, self.test_vm['name']),
                                        mcvirt_instance=self.mcvirt)
Esempio n. 3
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
            ))