def test_remove_tenants(self):
        vms = [(str(uuid.uuid4()), 'vm1')]
        
        privileges = self.get_privileges()
        default_datastore, default_privileges = self.get_default_datastore_and_privileges()
        error_info, tenant1 = self.auth_mgr.create_tenant('tenant1', 'Some tenant', default_datastore,
                                              default_privileges, vms, privileges)
        self.assertEqual(error_info, None)
        self.assertTrue(uuid.UUID(tenant1.id))
        
        vms = [(str(uuid.uuid4()), 'vm2'), (str(uuid.uuid4()), 'vm3')]
        privileges = []
        error_info, tenant2 = self.auth_mgr.create_tenant('tenant2', 'Some tenant', default_datastore,
                                              default_privileges, vms, privileges)
        self.assertEqual(error_info, None)
        self.assertTrue(uuid.UUID(tenant2.id))
     
        tenant2.set_datastore_access_privileges(self.auth_mgr.conn, privileges)
        error_info = self.auth_mgr.remove_tenant(tenant2.id, False)
        self.assertEqual(error_info, None)

        # Check tenants table
        error_info, tenants_row = auth.get_row_from_tenants_table(self.auth_mgr.conn, tenant2.id)
        self.assertEqual(error_info, None)
        self.assertEqual(tenants_row, None)

        # check vms table 
        error_info, vms_row = auth.get_row_from_vms_table(self.auth_mgr.conn, tenant2.id)
        self.assertEqual(error_info, None)
        self.assertEqual(vms_row, [])

        # check privileges table
        error_info, privileges_row = auth.get_row_from_privileges_table(self.auth_mgr.conn, tenant2.id)
        self.assertEqual(error_info, None)
        self.assertEqual(privileges_row, [])        
    def test_add_vms(self): 
        """ Test add_vms() API """

        vms = []
        privileges = []
        default_datastore, default_privileges = self.get_default_datastore_and_privileges()
        
        error_info, tenant1 = self.auth_mgr.create_tenant('tenant1', 'Some tenant', default_datastore,
                                              default_privileges, vms, privileges)
        self.assertEqual(error_info, None)
        self.assertTrue(uuid.UUID(tenant1.id))
        
        vm1_uuid = str(uuid.uuid4())
        vm2_uuid = str(uuid.uuid4())
        vms = [(vm1_uuid, 'vm1'), (vm2_uuid, 'vm2')]
        error_info = tenant1.add_vms(self.auth_mgr.conn, vms)
        self.assertEqual(error_info, None)

         # check vms table 
        error_info, vms_row = auth.get_row_from_vms_table(self.auth_mgr.conn,tenant1.id)
        self.assertEqual(error_info, None)
        expected_output = [(vm1_uuid, 'vm1', tenant1.id),
                           (vm2_uuid, 'vm2', tenant1.id) 
                          ]
        self.assertEqual(len(vms_row), 2)

        actual_output = [(vms_row[0][auth_data_const.COL_VM_ID],
                          vms_row[0][auth_data_const.COL_VM_NAME],
                          vms_row[0][auth_data_const.COL_TENANT_ID]),
                         (vms_row[1][auth_data_const.COL_VM_ID],
                          vms_row[1][auth_data_const.COL_VM_NAME],
                          vms_row[1][auth_data_const.COL_TENANT_ID]),
                        ]
        self.assertEqual(actual_output, expected_output)
Ejemplo n.º 3
0
    def test_add_vms(self):
        """ Test add_vms() API """

        vms = []
        privileges = []
        default_datastore = self.get_default_datastore()
        default_datastore_url = self.get_datastore_url(default_datastore)
        error_info, tenant1 = self.auth_mgr.create_tenant(name=self.tenant_name,
                                                          description='Some tenant',
                                                          vms=vms,
                                                          privileges=privileges)
        self.assertEqual(error_info, None)
        self.assertTrue(uuid.UUID(tenant1.id))

        vms = [(self.vm1_uuid, self.vm1_name), (self.vm2_uuid, self.vm2_name)]
        error_info = tenant1.add_vms(self.auth_mgr.conn, vms)
        self.assertEqual(error_info, None)

         # check vms table
        error_info, vms_row = auth.get_row_from_vms_table(self.auth_mgr.conn,tenant1.id)
        self.assertEqual(error_info, None)

        expected_output = [(self.vm1_uuid, tenant1.id),
                           (self.vm2_uuid, tenant1.id) 
                          ]
        self.assertEqual(len(vms_row), 2)

        actual_output = [(vms_row[0][auth_data_const.COL_VM_ID],
                          vms_row[0][auth_data_const.COL_TENANT_ID]),
                         (vms_row[1][auth_data_const.COL_VM_ID],
                          vms_row[1][auth_data_const.COL_TENANT_ID]),
                        ]
        self.assertEqual(actual_output, expected_output)
 def test_remove_vms(self):
     """
     """
         
     privileges = self.get_privileges()
     default_datastore, default_privileges = self.get_default_datastore_and_privileges()
     
     vm1_uuid = str(uuid.uuid4())
     vm2_uuid = str(uuid.uuid4())
     vms = [(vm1_uuid, 'vm1'), (vm2_uuid, 'vm2')]
     error_info, tenant1 = self.auth_mgr.create_tenant('tenant1', 'Some tenant', default_datastore,
                                           default_privileges, vms, privileges)
     self.assertEqual(error_info, None)
     self.assertTrue(uuid.UUID(tenant1.id))
     error_info = tenant1.remove_vms(self.auth_mgr.conn, vms)
     self.assertEqual(error_info, None)
     error_info, vms_row = auth.get_row_from_vms_table(self.auth_mgr.conn, tenant1.id)
     self.assertEqual(error_info, None)
     self.assertEqual(vms_row, [])
Ejemplo n.º 5
0
    def test_remove_tenants(self):
        vms = [(self.vm1_uuid, self.vm1_name)]

        privileges = self.get_privileges()
        default_datastore = self.get_default_datastore()
        default_datastore_url = self.get_datastore_url(default_datastore)

        error_info, tenant1 = self.auth_mgr.create_tenant(name=self.tenant_name,
                                                          description='Some tenant',
                                                          vms=vms,
                                                          privileges=privileges)

        self.assertEqual(error_info, None)
        self.assertTrue(uuid.UUID(tenant1.id))
        vms = [(self.vm2_uuid, self.vm2_name), (self.vm3_uuid, self.vm3_name)]
        privileges = []
        error_info, tenant2 = self.auth_mgr.create_tenant(name=self.tenant_2_name,
                                                          description='Some tenant',
                                                          vms=vms,
                                                          privileges=privileges)

        self.assertEqual(error_info, None)
        self.assertTrue(uuid.UUID(tenant2.id))

        tenant2.set_datastore_access_privileges(self.auth_mgr.conn, privileges)
        error_info = self.auth_mgr.remove_tenant(tenant2.id, False)
        self.assertEqual(error_info, None)

        # Check tenants table
        error_info, tenants_row = auth.get_row_from_tenants_table(self.auth_mgr.conn, tenant2.id)
        self.assertEqual(error_info, None)
        self.assertEqual(tenants_row, None)

        # check vms table
        error_info, vms_row = auth.get_row_from_vms_table(self.auth_mgr.conn, tenant2.id)
        self.assertEqual(error_info, None)
        self.assertEqual(vms_row, [])

        # check privileges table
        error_info, privileges_row = auth.get_row_from_privileges_table(self.auth_mgr.conn, tenant2.id)
        self.assertEqual(error_info, None)
        self.assertEqual(privileges_row, [])
Ejemplo n.º 6
0
    def test_remove_vms(self):
        """
        """

        privileges = self.get_privileges()
        default_datastore = self.get_default_datastore()
        default_datastore_url = self.get_datastore_url(default_datastore)

        vms = [(self.vm1_uuid, self.vm1_name), (self.vm2_uuid, self.vm2_name)]
        error_info, tenant1 = self.auth_mgr.create_tenant(name=self.tenant_name,
                                                          description='Some tenant',
                                                          vms=vms,
                                                          privileges=privileges)

        self.assertEqual(error_info, None)
        self.assertTrue(uuid.UUID(tenant1.id))
        error_info = tenant1.remove_vms(self.auth_mgr.conn, vms)
        self.assertEqual(error_info, None)
        error_info, vms_row = auth.get_row_from_vms_table(self.auth_mgr.conn, tenant1.id)
        self.assertEqual(error_info, None)
        self.assertEqual(vms_row, [])
    def test_create_tenant(self):
        """ Test create_tenant() API """

        vm1_uuid = str(uuid.uuid4())
        vms = [(vm1_uuid, 'vm1')]
        
        #privileges = []
        privileges = self.get_privileges()
        default_datastore, default_privileges = self.get_default_datastore_and_privileges()
        error_info, tenant1 = self.auth_mgr.create_tenant('tenant1', 'Some tenant', default_datastore,
                                              default_privileges, vms, privileges)
        self.assertEqual(error_info, None)                                            
        self.assertTrue(uuid.UUID(tenant1.id))

        # Check tenants table
        error_info, tenants_row = auth.get_row_from_tenants_table(self.auth_mgr.conn, tenant1.id)
        self.assertEqual(error_info, None)
        expected_output = [tenant1.id,
                           'tenant1',
                           'Some tenant',
                           'default_ds']
        actual_output = [tenants_row[auth_data_const.COL_ID],
                         tenants_row[auth_data_const.COL_NAME],
                         tenants_row[auth_data_const.COL_DESCRIPTION],
                         tenants_row[auth_data_const.COL_DEFAULT_DATASTORE]
                        ]
                          
        self.assertEqual(actual_output, expected_output)

        # check vms table 
        error_info, vms_row = auth.get_row_from_vms_table(self.auth_mgr.conn, tenant1.id)
        self.assertEqual(error_info, None)
        expected_output = [vm1_uuid,
                           'vm1',
                           tenant1.id]
        self.assertEqual(len(vms_row), 1)

        actual_output = [vms_row[0][auth_data_const.COL_VM_ID],
                         vms_row[0][auth_data_const.COL_VM_NAME],
                         vms_row[0][auth_data_const.COL_TENANT_ID]
                        ]
        self.assertEqual(actual_output, expected_output)

        # check privileges table
        error_info, privileges_row = auth.get_row_from_privileges_table(self.auth_mgr.conn, tenant1.id)
        self.assertEqual(error_info, None)
        self.assertEqual(len(privileges_row), 2)

        expected_privileges = [tenant1.id,
                               privileges[0][auth_data_const.COL_DATASTORE],
                               privileges[0][auth_data_const.COL_GLOBAL_VISIBILITY],
                               privileges[0][auth_data_const.COL_CREATE_VOLUME],
                               privileges[0][auth_data_const.COL_DELETE_VOLUME],
                               privileges[0][auth_data_const.COL_MOUNT_VOLUME],
                               privileges[0][auth_data_const.COL_MAX_VOLUME_SIZE],
                               privileges[0][auth_data_const.COL_USAGE_QUOTA]
                              ]
        expected_default_privileges = [tenant1.id,
                                       default_privileges[auth_data_const.COL_DATASTORE],
                                       default_privileges[auth_data_const.COL_GLOBAL_VISIBILITY],
                                       default_privileges[auth_data_const.COL_CREATE_VOLUME],
                                       default_privileges[auth_data_const.COL_DELETE_VOLUME],
                                       default_privileges[auth_data_const.COL_MOUNT_VOLUME],
                                       default_privileges[auth_data_const.COL_MAX_VOLUME_SIZE],
                                       default_privileges[auth_data_const.COL_USAGE_QUOTA]
                                      ]

        expected_output = [expected_privileges, 
                           expected_default_privileges
                          ]
         
        actual_privileges = [privileges_row[0][auth_data_const.COL_TENANT_ID],
                             privileges_row[0][auth_data_const.COL_DATASTORE],
                             privileges_row[0][auth_data_const.COL_GLOBAL_VISIBILITY],
                             privileges_row[0][auth_data_const.COL_CREATE_VOLUME],
                             privileges_row[0][auth_data_const.COL_DELETE_VOLUME],
                             privileges_row[0][auth_data_const.COL_MOUNT_VOLUME],
                             privileges_row[0][auth_data_const.COL_MAX_VOLUME_SIZE],
                             privileges_row[0][auth_data_const.COL_USAGE_QUOTA]
                             ]
        actual_default_privileges = [privileges_row[1][auth_data_const.COL_TENANT_ID],
                                     privileges_row[1][auth_data_const.COL_DATASTORE],
                                     privileges_row[1][auth_data_const.COL_GLOBAL_VISIBILITY],
                                     privileges_row[1][auth_data_const.COL_CREATE_VOLUME],
                                     privileges_row[1][auth_data_const.COL_DELETE_VOLUME],
                                     privileges_row[1][auth_data_const.COL_MOUNT_VOLUME],
                                     privileges_row[1][auth_data_const.COL_MAX_VOLUME_SIZE],
                                     privileges_row[1][auth_data_const.COL_USAGE_QUOTA]
                                    ]
        actual_output = [actual_privileges, actual_default_privileges]
        self.assertEqual(actual_output, expected_output)        
Ejemplo n.º 8
0
    def test_create_tenant(self):
        """ Test create_tenant() API """

        vm1_uuid = str(uuid.uuid4())
        vms = [(vm1_uuid)]
        privileges = self.get_privileges()
        default_datastore = self.get_default_datastore()
        default_datastore_url = self.get_datastore_url(default_datastore)
        error_info, tenant1 = self.auth_mgr.create_tenant(name='tenant1', 
                                                          description='Some tenant', 
                                                          vms=vms, 
                                                          privileges=privileges)
        self.assertEqual(error_info, None)                                            
        self.assertTrue(uuid.UUID(tenant1.id))

        # Check tenants table
        error_info, tenants_row = auth.get_row_from_tenants_table(self.auth_mgr.conn, tenant1.id)
        self.assertEqual(error_info, None)
        expected_output = [tenant1.id,
                           'tenant1',
                           'Some tenant']

        actual_output = [tenants_row[auth_data_const.COL_ID],
                         tenants_row[auth_data_const.COL_NAME],
                         tenants_row[auth_data_const.COL_DESCRIPTION]
                        ]
                          
        self.assertEqual(actual_output, expected_output)

        # check vms table 
        error_info, vms_row = auth.get_row_from_vms_table(self.auth_mgr.conn, tenant1.id)
        self.assertEqual(error_info, None)
        expected_output = [vm1_uuid,
                           tenant1.id]
        self.assertEqual(len(vms_row), 1)

        actual_output = [vms_row[0][auth_data_const.COL_VM_ID],
                         vms_row[0][auth_data_const.COL_TENANT_ID]
                        ]
        self.assertEqual(actual_output, expected_output)

        # check privileges table
        error_info, privileges_row = auth.get_row_from_privileges_table(self.auth_mgr.conn, tenant1.id)
        self.assertEqual(error_info, None)
        self.assertEqual(len(privileges_row), 1)

        expected_privileges = [tenant1.id,
                               privileges[0][auth_data_const.COL_DATASTORE_URL],
                               privileges[0][auth_data_const.COL_ALLOW_CREATE],
                               privileges[0][auth_data_const.COL_MAX_VOLUME_SIZE],
                               privileges[0][auth_data_const.COL_USAGE_QUOTA]
                              ]
        
        expected_output = [expected_privileges 
                          ]
         
        actual_privileges = [privileges_row[0][auth_data_const.COL_TENANT_ID],
                             privileges_row[0][auth_data_const.COL_DATASTORE_URL],
                             privileges_row[0][auth_data_const.COL_ALLOW_CREATE],
                             privileges_row[0][auth_data_const.COL_MAX_VOLUME_SIZE],
                             privileges_row[0][auth_data_const.COL_USAGE_QUOTA]
                             ]

        actual_output = [actual_privileges]
        self.assertEqual(actual_output, expected_output)        
    def test_create_tenant(self):
        """ Test create_tenant() API """

        vms = [(self.vm1_uuid, self.vm1_name)]
        privileges = self.get_privileges()
        default_datastore = self.get_default_datastore()
        default_datastore_url = self.get_datastore_url(default_datastore)
        error_info, tenant1 = self.auth_mgr.create_tenant(name=self.tenant_name,
                                                          description='Some tenant',
                                                          vms=vms,
                                                          privileges=privileges)
        self.assertEqual(error_info, None)
        self.assertTrue(uuid.UUID(tenant1.id))

        # Check tenants table
        error_info, tenants_row = auth.get_row_from_tenants_table(self.auth_mgr.conn, tenant1.id)
        self.assertEqual(error_info, None)
        expected_output = [tenant1.id,
                           self.tenant_name,
                           'Some tenant']

        actual_output = [tenants_row[auth_data_const.COL_ID],
                         tenants_row[auth_data_const.COL_NAME],
                         tenants_row[auth_data_const.COL_DESCRIPTION]
                        ]

        self.assertEqual(actual_output, expected_output)

        # check vms table
        error_info, vms_row = auth.get_row_from_vms_table(self.auth_mgr.conn, tenant1.id)
        self.assertEqual(error_info, None)
        expected_output = [self.vm1_uuid,
                           tenant1.id]
        self.assertEqual(len(vms_row), 1)

        actual_output = [vms_row[0][auth_data_const.COL_VM_ID],
                         vms_row[0][auth_data_const.COL_TENANT_ID]
                        ]
        self.assertEqual(actual_output, expected_output)

        # check privileges table
        error_info, privileges_row = auth.get_row_from_privileges_table(self.auth_mgr.conn, tenant1.id)
        self.assertEqual(error_info, None)
        self.assertEqual(len(privileges_row), 1)

        expected_privileges = [tenant1.id,
                               privileges[0][auth_data_const.COL_DATASTORE_URL],
                               privileges[0][auth_data_const.COL_ALLOW_CREATE],
                               privileges[0][auth_data_const.COL_MAX_VOLUME_SIZE],
                               privileges[0][auth_data_const.COL_USAGE_QUOTA]
                              ]

        expected_output = [expected_privileges
                          ]

        actual_privileges = [privileges_row[0][auth_data_const.COL_TENANT_ID],
                             privileges_row[0][auth_data_const.COL_DATASTORE_URL],
                             privileges_row[0][auth_data_const.COL_ALLOW_CREATE],
                             privileges_row[0][auth_data_const.COL_MAX_VOLUME_SIZE],
                             privileges_row[0][auth_data_const.COL_USAGE_QUOTA]
                             ]

        actual_output = [actual_privileges]
        self.assertEqual(actual_output, expected_output)