def setUp(self): VncApiMock.init() DBMock.init() vnc_kubernetes.VncKubernetes.reset() self.args = Mock() self.args.admin_user = "******" self.args.admin_password = "******" self.args.admin_tenant = "default" self.args.vnc_endpoint_ip = '127.0.0.1' self.args.vnc_endpoint_port = "8082" self.args.auth_token_url = "token" self.args.cluster_project = None self.args.cluster_network = None self.args.cluster_pod_network = None self.args.cluster_service_network = None self.args.pod_subnets = ['10.10.0.0/16'] self.args.service_subnets = ['192.168.0.0/24'] self.args.kubernetes_api_secure_port = "8443" self.args.auth_user = "******" self.args.auth_password = "******" self.args.auth_tenant = "default" self.args.cassandra_server_list = () api = VncApiMock(self.args.auth_user, self.args.auth_password, self.args.auth_tenant, self.args.vnc_endpoint_ip, self.args.vnc_endpoint_port, self.args.auth_token_url) domain_uuid = api.domain_create(Domain("default-domain")) domain = api.domain_read(id=domain_uuid) proj_uuid = api.project_create( Project("default-project", parent_obj=domain)) proj = api.project_read(id=proj_uuid) net = VirtualNetwork("ip-fabric", proj) api.virtual_network_create(net)
def update(res_type, obj): if not obj.uuid: obj.uuid = VncApiMock.name_to_id(res_type, obj.name) if obj.uuid is None: raise NoIdError("Object does not exist.") if obj.uuid not in DBMock.get_dict(res_type.replace('-', '_')): raise NoIdError("Object does not exist.") DBMock.update(res_type.replace('-', '_'), obj.uuid, VncApiMock.object_to_dict(obj))
def create(res_type, obj): if obj.name in VncApiMock.name_to_uuid.get(res_type): raise RefsExistError() obj.uuid = VncApiMock._alloc_uuid() DBMock.create(res_type.replace('-', '_'), obj.uuid, VncApiMock.object_to_dict(obj)) VncApiMock.name_to_uuid.get(res_type)[obj.name] = obj.uuid return obj.uuid
def delete(res_type, fq_name=None, id=None, ifmap_id=None): (args_ok, result) = VncApiMock._read_args_to_id(res_type, fq_name=fq_name, id=id) if not args_ok: return result if result is None: raise NoIdError("Object does not exist.") obj = DBMock.read(res_type.replace('-', '_'), [result]) VncApiMock.name_to_uuid.pop(obj.get_name()) DBMock.delete(res_type.replace('-', '_'), result)
def verify_if_created(self, res_type, name, parent_fq_name): obj = VncApiMock.read(res_type, fq_name=parent_fq_name+[name]) self.assertEquals(name, obj.name) uuid = obj.uuid ok, obj_list = DBMock.read(res_type.replace('-', '_'), [uuid]) self.assertEquals(True, ok) self.assertEquals(parent_fq_name+[name], obj_list[0]['fq_name']) return obj
def setUp(self): VncApiMock.init() DBMock.init() vnc_kubernetes.VncKubernetes.reset() self.args = Mock() self.args.admin_user = "******" self.args.admin_password = "******" self.args.admin_tenant = "default" self.args.vnc_endpoint_ip = '127.0.0.1' self.args.vnc_endpoint_port = "8082" self.args.auth_token_url = "token" self.args.cluster_project = None self.args.cluster_network = None self.args.cluster_pod_network = None self.args.cluster_service_network = None self.args.cluster_name = "cluster" self.args.pod_subnets = ['10.10.0.0/16'] self.args.ip_fabric_subnets = ['20.20.0.0/16'] self.args.service_subnets = ['192.168.0.0/24'] self.args.kubernetes_api_secure_port = "8443" self.args.auth_user = "******" self.args.auth_password = "******" self.args.auth_tenant = "default" self.args.cassandra_server_list = () self.args.aps_name="test-aps" self.args.rabbit_port = None self.args.collectors = "" api = VncApiMock( self.args.auth_user, self.args.auth_password, self.args.auth_tenant, self.args.vnc_endpoint_ip, self.args.vnc_endpoint_port, self.args.auth_token_url ) domain_uuid = api.domain_create(Domain("default-domain")) domain = api.domain_read(id=domain_uuid) proj_uuid = api.project_create(Project("default-project", parent_obj=domain)) proj = api.project_read(id=proj_uuid) net = VirtualNetwork("ip-fabric", proj) api.virtual_network_create(net)
def setUp(self): VncApiMock.init() DBMock.init() vnc_kubernetes.VncKubernetes.reset() self.args = Mock() self.args.admin_user = "******" self.args.admin_password = "******" self.args.admin_tenant = "default" self.args.vnc_endpoint_ip = '127.0.0.1' self.args.vnc_endpoint_port = "8082" self.args.auth_token_url = "token" self.args.cluster_project = None self.args.cluster_network = None self.args.pod_subnets = ['10.10.0.0/16'] self.args.service_subnets = ['192.168.0.0/24'] self.args.kubernetes_api_secure_port = "8443" self.args.auth_user = "******" self.args.auth_password = "******" self.args.auth_tenant = "default" self.args.cassandra_server_list = ()
def read(res_type, fq_name=None, fq_name_str=None, id=None, fields=None): (args_ok, result) = VncApiMock._read_args_to_id(res_type, fq_name, fq_name_str, id) if not args_ok: return result if result is None: raise NoIdError("Object does not exist.") ok, ret = DBMock.read(res_type.replace('-', '_'), [result]) if (not ok) or (len(ret) < 1): raise NoIdError("Object does not exist.") return VncApiMock.object_from_dict(res_type, ret[0])
def _list(res_type, parent_id=None, parent_fq_name=None, obj_uuids=None, back_ref_id=None, fields=None, detail=False, count=False, filters=None, shared=False): ret = [] for obj_dict in list( DBMock.get_dict(res_type.replace('-', '_')).values()): obj = VncApiMock.object_from_dict(res_type, obj_dict) if parent_id is not None and parent_id != VncApiMock.name_to_uuid( obj.parent_name()): continue if parent_fq_name is not None and parent_fq_name != obj.get_parent_fq_name( ): continue if obj_uuids is not None and obj.uuid not in obj_uuids: continue ret.append(obj) return ret
def test_sync_km(self, mock_vnc_amqp_handle_init): # Put some objects to database DBMock.create('domain', '123', { 'uuid': '123', 'fq_name': ['test-domain'] }) DBMock.create( 'project', '234', { 'uuid': '234', 'fq_name': ['test-domain', 'test-proj-1'], 'parent_uuid': '123' }) DBMock.create( 'project', '345', { 'uuid': '345', 'fq_name': ['test-domain', 'test-proj-2'], 'parent_uuid': '123' }) mock_vnc_amqp_handle = Mock() mock_vnc_amqp_handle_init.return_value = mock_vnc_amqp_handle vnc_kubernetes.VncKubernetes(self.args, Mock()) mock_vnc_amqp_handle.establish.assert_called_once_with() # check if KM dictionaries are synchronized with database self.assertEquals(2, len(vnc_kubernetes.DomainKM.list_obj())) self.assertEquals(5, len(vnc_kubernetes.ProjectKM.list_obj())) obj = vnc_kubernetes.DomainKM.get('123') self.assertIsNotNone(obj) self.assertEquals(['test-domain'], obj.fq_name) self.assertEquals('123', obj.uuid) obj = vnc_kubernetes.ProjectKM.get('234') self.assertIsNotNone(obj) self.assertEquals('test-proj-1', obj.name) self.assertEquals(['test-domain', 'test-proj-1'], obj.fq_name) self.assertEquals('234', obj.uuid) obj = vnc_kubernetes.ProjectKM.get('345') self.assertIsNotNone(obj) self.assertEquals('test-proj-2', obj.name) self.assertEquals(['test-domain', 'test-proj-2'], obj.fq_name) self.assertEquals('345', obj.uuid)
def test_sync_km(self, mock_vnc_amqp_handle_init): # Put some objects to database DBMock.create('domain', '123', { 'uuid': '123', 'fq_name': ['test-domain'] }) DBMock.create('project', '234', { 'uuid': '234', 'fq_name': ['test-domain', 'test-proj-1'], 'parent_uuid': '123' }) DBMock.create('project', '345', { 'uuid': '345', 'fq_name': ['test-domain', 'test-proj-2'], 'parent_uuid': '123' }) mock_vnc_amqp_handle = Mock() mock_vnc_amqp_handle_init.return_value = mock_vnc_amqp_handle vnc_kubernetes.VncKubernetes(self.args, Mock()) mock_vnc_amqp_handle.establish.assert_called_once_with() # check if KM dictionaries are synchronized with database self.assertEquals(1, len(vnc_kubernetes.DomainKM.list_obj())) self.assertEquals(4, len(vnc_kubernetes.ProjectKM.list_obj())) obj = vnc_kubernetes.DomainKM.get('123') self.assertIsNotNone(obj) self.assertEquals(['test-domain'], obj.fq_name) self.assertEquals('123', obj.uuid) obj = vnc_kubernetes.ProjectKM.get('234') self.assertIsNotNone(obj) self.assertEquals('test-proj-1', obj.name) self.assertEquals(['test-domain', 'test-proj-1'], obj.fq_name) self.assertEquals('234', obj.uuid) obj = vnc_kubernetes.ProjectKM.get('345') self.assertIsNotNone(obj) self.assertEquals('test-proj-2', obj.name) self.assertEquals(['test-domain', 'test-proj-2'], obj.fq_name) self.assertEquals('345', obj.uuid)
def init(): DBMock.init() VncApiMock.name_to_uuid = {} for object_type, resource_type in all_resource_type_tuples: VncApiMock.name_to_uuid[resource_type] = {} VncApiMock.next_uuid = 0