def test_remove_security_service(self): security_dict1 = { 'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type' } db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict['id'], security_dict1['id']) db_api.share_network_remove_security_service(self.fake_context, self.share_nw_dict['id'], security_dict1['id']) result = sqlalchemy_api.model_query( self.fake_context, models.ShareNetworkSecurityServiceAssociation).\ filter_by(security_service_id=security_dict1['id']).\ filter_by(share_network_id=self.share_nw_dict['id']).first() self.assertTrue(result is None) share_nw_ref = db_api.share_network_get(self.fake_context, self.share_nw_dict['id']) self.assertEqual(len(share_nw_ref['security_services']), 0)
def test_add_security_service_association_error_status_active(self): security_dict1 = { "id": "fake security service id1", "project_id": self.fake_context.project_id, "type": "fake type", } db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.share_network_update(self.fake_context, self.share_nw_dict["id"], {"status": constants.STATUS_ACTIVE}) db_api.security_service_create(self.fake_context, security_dict1) self.assertRaises( exception.ShareNetworkSecurityServiceAssociationError, db_api.share_network_add_security_service, self.fake_context, self.share_nw_dict["id"], security_dict1["id"], ) assoc_ref = ( sqlalchemy_api.model_query(self.fake_context, models.ShareNetworkSecurityServiceAssociation) .filter_by(security_service_id=security_dict1["id"]) .filter_by(share_network_id=self.share_nw_dict["id"]) .first() ) self.assertTrue(assoc_ref is None)
def test_remove_security_service(self): security_dict1 = {'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type'} db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict['id'], security_dict1['id']) db_api.share_network_remove_security_service(self.fake_context, self.share_nw_dict['id'], security_dict1['id']) result = sqlalchemy_api.model_query( self.fake_context, models.ShareNetworkSecurityServiceAssociation).\ filter_by(security_service_id=security_dict1['id']).\ filter_by(share_network_id=self.share_nw_dict['id']).first() self.assertTrue(result is None) share_nw_ref = db_api.share_network_get(self.fake_context, self.share_nw_dict['id']) self.assertEqual(len(share_nw_ref['security_services']), 0)
def test_get_with_two_security_services(self): security_dict1 = { 'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type' } security_dict2 = { 'id': 'fake security service id2', 'project_id': self.fake_context.project_id, 'type': 'fake type' } db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) db_api.security_service_create(self.fake_context, security_dict2) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict['id'], security_dict1['id']) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict['id'], security_dict2['id']) result = db_api.share_network_get(self.fake_context, self.share_nw_dict['id']) self.assertEqual(len(result['security_services']), 2)
def test_add_security_service_association_error_status_active(self): security_dict1 = {'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type'} db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.share_network_update(self.fake_context, self.share_nw_dict['id'], {'status': constants.STATUS_ACTIVE}) db_api.security_service_create(self.fake_context, security_dict1) self.assertRaises( exception.ShareNetworkSecurityServiceAssociationError, db_api.share_network_add_security_service, self.fake_context, self.share_nw_dict['id'], security_dict1['id']) assoc_ref = sqlalchemy_api.model_query( self.fake_context, models.ShareNetworkSecurityServiceAssociation).\ filter_by(security_service_id=security_dict1['id']).\ filter_by(share_network_id=self.share_nw_dict['id']).first() self.assertTrue(assoc_ref is None)
def test_create_with_duplicated_id(self): db_api.security_service_create(self.fake_context, security_service_dict) self.assertRaises(db_exception.DBDuplicateEntry, db_api.security_service_create, self.fake_context, security_service_dict)
def test_get_all_one_record(self): db_api.security_service_create(self.fake_context, security_service_dict) result = db_api.security_service_get_all(self.fake_context) self.assertEqual(len(result), 1) self._check_expected_fields(result[0], security_service_dict)
def test_get(self): db_api.security_service_create(self.fake_context, security_service_dict) result = db_api.security_service_get(self.fake_context, security_service_dict['id']) self._check_expected_fields(result, security_service_dict)
def test_get_all_one_record(self): db_api.security_service_create(self.fake_context, security_service_dict) result = db_api.security_service_get_all(self.fake_context) self.assertEqual(len(result), 1) self._check_expected_fields(result[0], security_service_dict)
def test_create_with_duplicated_id(self): db_api.security_service_create(self.fake_context, security_service_dict) self.assertRaises(db_exception.DBDuplicateEntry, db_api.security_service_create, self.fake_context, security_service_dict)
def test_get(self): db_api.security_service_create(self.fake_context, security_service_dict) result = db_api.security_service_get(self.fake_context, security_service_dict['id']) self._check_expected_fields(result, security_service_dict)
def test_delete(self): db_api.security_service_create(self.fake_context, security_service_dict) db_api.security_service_delete(self.fake_context, security_service_dict['id']) self.assertRaises(exception.SecurityServiceNotFound, db_api.security_service_get, self.fake_context, security_service_dict['id'])
def test_get_all_two_records(self): dict1 = security_service_dict dict2 = security_service_dict.copy() dict2['id'] = 'fake id 2' db_api.security_service_create(self.fake_context, dict1) db_api.security_service_create(self.fake_context, dict2) result = db_api.security_service_get_all(self.fake_context) self.assertEqual(len(result), 2)
def test_delete(self): db_api.security_service_create(self.fake_context, security_service_dict) db_api.security_service_delete(self.fake_context, security_service_dict['id']) self.assertRaises(exception.SecurityServiceNotFound, db_api.security_service_get, self.fake_context, security_service_dict['id'])
def test_remove_security_service_not_found_02(self): security_dict1 = { 'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type' } share_nw_id = 'unknown share network' db_api.security_service_create(self.fake_context, security_dict1) self.assertRaises(exception.ShareNetworkNotFound, db_api.share_network_remove_security_service, self.fake_context, share_nw_id, security_dict1['id'])
def test_remove_security_service_not_found_02(self): security_dict1 = {'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type'} share_nw_id = 'unknown share network' db_api.security_service_create(self.fake_context, security_dict1) self.assertRaises(exception.ShareNetworkNotFound, db_api.share_network_remove_security_service, self.fake_context, share_nw_id, security_dict1['id'])
def test_get_all_two_records(self): dict1 = security_service_dict dict2 = security_service_dict.copy() dict2['id'] = 'fake id 2' db_api.security_service_create(self.fake_context, dict1) db_api.security_service_create(self.fake_context, dict2) result = db_api.security_service_get_all(self.fake_context) self.assertEqual(len(result), 2)
def test_security_services_relation(self): security_dict1 = {'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type'} db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) result = db_api.share_network_get(self.fake_context, self.share_nw_dict['id']) self.assertEqual(len(result['security_services']), 0)
def test_security_services_relation(self): security_dict1 = {'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type'} db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) result = db_api.share_network_get(self.fake_context, self.share_nw_dict['id']) self.assertEqual(len(result['security_services']), 0)
def test_security_services_relation(self): security_dict1 = { "id": "fake security service id1", "project_id": self.fake_context.project_id, "type": "fake type", } db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) result = db_api.share_network_get(self.fake_context, self.share_nw_dict["id"]) self.assertEqual(len(result["security_services"]), 0)
def test_remove_security_service_dissociation_error(self): security_dict1 = {'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type'} db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) self.assertRaises( exception.ShareNetworkSecurityServiceDissociationError, db_api.share_network_remove_security_service, self.fake_context, self.share_nw_dict['id'], security_dict1['id'])
def test_remove_security_service_dissociation_error(self): security_dict1 = { 'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type' } db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) self.assertRaises( exception.ShareNetworkSecurityServiceDissociationError, db_api.share_network_remove_security_service, self.fake_context, self.share_nw_dict['id'], security_dict1['id'])
def test_get_with_one_security_service(self): security_dict1 = { "id": "fake security service id1", "project_id": self.fake_context.project_id, "type": "fake type", } db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict["id"], security_dict1["id"]) result = db_api.share_network_get(self.fake_context, self.share_nw_dict["id"]) self.assertEqual(len(result["security_services"]), 1) self._check_fields(expected=security_dict1, actual=result["security_services"][0])
def test_remove_security_service_not_found_02(self): security_dict1 = { "id": "fake security service id1", "project_id": self.fake_context.project_id, "type": "fake type", } share_nw_id = "unknown share network" db_api.security_service_create(self.fake_context, security_dict1) self.assertRaises( exception.ShareNetworkNotFound, db_api.share_network_remove_security_service, self.fake_context, share_nw_id, security_dict1["id"], )
def test_get_with_one_security_service(self): security_dict1 = {'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type'} db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict['id'], security_dict1['id']) result = db_api.share_network_get(self.fake_context, self.share_nw_dict['id']) self.assertEqual(len(result['security_services']), 1) self._check_fields(expected=security_dict1, actual=result['security_services'][0])
def test_remove_security_service_dissociation_error(self): security_dict1 = { "id": "fake security service id1", "project_id": self.fake_context.project_id, "type": "fake type", } db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) self.assertRaises( exception.ShareNetworkSecurityServiceDissociationError, db_api.share_network_remove_security_service, self.fake_context, self.share_nw_dict["id"], security_dict1["id"], )
def test_get_with_one_security_service(self): security_dict1 = {'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type'} db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict['id'], security_dict1['id']) result = db_api.share_network_get(self.fake_context, self.share_nw_dict['id']) self.assertEqual(len(result['security_services']), 1) self._check_fields(expected=security_dict1, actual=result['security_services'][0])
def test_update(self): update_dict = {'dns_ip': 'new dns', 'server': 'new ldap server', 'domain': 'new ldap domain', 'sid': 'new sid', 'password': '******', 'name': 'new whatever', 'description': 'new nevermind', 'status': constants.STATUS_ERROR} db_api.security_service_create(self.fake_context, security_service_dict) result = db_api.security_service_update(self.fake_context, security_service_dict['id'], update_dict) self._check_expected_fields(result, update_dict)
def test_add_security_service(self): security_dict1 = { "id": "fake security service id1", "project_id": self.fake_context.project_id, "type": "fake type", } db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict["id"], security_dict1["id"]) result = ( sqlalchemy_api.model_query(self.fake_context, models.ShareNetworkSecurityServiceAssociation) .filter_by(security_service_id=security_dict1["id"]) .filter_by(share_network_id=self.share_nw_dict["id"]) .first() ) self.assertTrue(result is not None)
def test_get_all_by_project(self): dict1 = security_service_dict dict2 = security_service_dict.copy() dict2['id'] = 'fake id 2' dict2['project_id'] = 'fake project 2' db_api.security_service_create(self.fake_context, dict1) db_api.security_service_create(self.fake_context, dict2) result1 = db_api.security_service_get_all_by_project( self.fake_context, dict1['project_id']) self.assertEqual(len(result1), 1) self._check_expected_fields(result1[0], dict1) result2 = db_api.security_service_get_all_by_project( self.fake_context, dict2['project_id']) self.assertEqual(len(result2), 1) self._check_expected_fields(result2[0], dict2)
def test_get_with_two_security_services(self): security_dict1 = { "id": "fake security service id1", "project_id": self.fake_context.project_id, "type": "fake type", } security_dict2 = { "id": "fake security service id2", "project_id": self.fake_context.project_id, "type": "fake type", } db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) db_api.security_service_create(self.fake_context, security_dict2) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict["id"], security_dict1["id"]) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict["id"], security_dict2["id"]) result = db_api.share_network_get(self.fake_context, self.share_nw_dict["id"]) self.assertEqual(len(result["security_services"]), 2)
def test_get_with_two_security_services(self): security_dict1 = {'id': 'fake security service id1', 'project_id': self.fake_context.project_id, 'type': 'fake type'} security_dict2 = {'id': 'fake security service id2', 'project_id': self.fake_context.project_id, 'type': 'fake type'} db_api.share_network_create(self.fake_context, self.share_nw_dict) db_api.security_service_create(self.fake_context, security_dict1) db_api.security_service_create(self.fake_context, security_dict2) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict['id'], security_dict1['id']) db_api.share_network_add_security_service(self.fake_context, self.share_nw_dict['id'], security_dict2['id']) result = db_api.share_network_get(self.fake_context, self.share_nw_dict['id']) self.assertEqual(len(result['security_services']), 2)
def test_get_all_by_project(self): dict1 = security_service_dict dict2 = security_service_dict.copy() dict2['id'] = 'fake id 2' dict2['project_id'] = 'fake project 2' db_api.security_service_create(self.fake_context, dict1) db_api.security_service_create(self.fake_context, dict2) result1 = db_api.security_service_get_all_by_project( self.fake_context, dict1['project_id']) self.assertEqual(len(result1), 1) self._check_expected_fields(result1[0], dict1) result2 = db_api.security_service_get_all_by_project( self.fake_context, dict2['project_id']) self.assertEqual(len(result2), 1) self._check_expected_fields(result2[0], dict2)