def _calculate_instance_properties(self, pool, vip): """ ServiceInstance settings - right network: public side, determined by the vip - left network: backend, determined by the pool subnet """ props = ServiceInstanceType() vmi = self._get_virtual_ip_interface(vip) if not vmi: return None vnet_refs = vmi.get_virtual_network_refs() if vnet_refs is None: return None props.right_virtual_network = ':'.join(vnet_refs[0]['to']) props.right_ip_address = self._get_interface_address(vmi) if props.right_ip_address is None: return None pool_attrs = pool.get_loadbalancer_pool_properties() backnet_id = utils.get_subnet_network_id(self._api, pool_attrs.subnet_id) if backnet_id != vnet_refs[0]['uuid']: try: vnet = self._api.virtual_network_read(id=backnet_id) except NoIdError as ex: LOG.error(ex) return None props.left_virtual_network = vnet.get_fq_name().join(':') return props
def _calculate_instance_properties(self, pool, vip): """ ServiceInstance settings - right network: public side, determined by the vip - left network: backend, determined by the pool subnet """ props = ServiceInstanceType() vmi = self._get_virtual_ip_interface(vip) if not vmi: return None vnet_refs = vmi.get_virtual_network_refs() if vnet_refs is None: return None props.right_virtual_network = ':'.join(vnet_refs[0]['to']) props.right_ip_address = self._get_interface_address(vmi) if props.right_ip_address is None: return None pool_attrs = pool.get_loadbalancer_pool_properties() backnet_id = utils.get_subnet_network_id( self._api, pool_attrs.subnet_id) if backnet_id != vnet_refs[0]['uuid']: try: vnet = self._api.virtual_network_read(id=backnet_id) except NoIdError as ex: LOG.error(ex) return None props.left_virtual_network = vnet.get_fq_name().join(':') return props
def test_vm_instance(self, cassandra_init_mock): logging.debug("init") self._api_client = mock.Mock() arguments = Arguments() with patch.object(logging.handlers, 'RotatingFileHandler'): self._svc_monitor = SvcMonitor(arguments) self._svc_monitor.post_init(self._api_client, arguments) self._svc_monitor.db._svc_si_cf = {} self._svc_monitor.db._svc_vm_cf = mock.Mock() self._svc_monitor._novaclient_get = mock.Mock() identities = { 'service-template': 'default-domain:test:template1', 'service-instance': 'default-domain:test:service1' } tmpl_attr = ServiceTemplateType() tmpl_attr.service_mode = 'in-network-nat' tmpl_attr.service_type = 'firewall' tmpl_attr.image_name = 'test-template' tmpl_attr.service_virtualization_type = 'virtual-machine' template = ServiceTemplate(service_template_properties=tmpl_attr) template.uuid = 'aaa' svc_attr = ServiceInstanceType() svc_attr.left_virtual_network = 'default-project:demo:test' svc_attr.right_virtual_network = 'default-project:admin:public' svc_attr.scale_out = ServiceScaleOutType() service = ServiceInstance('test-instance', service_instance_properties=svc_attr) service.uuid = 'bbb' self._api_client.service_template_read.return_value = template self._api_client.service_instance_read.return_value = service with contextlib.nested( patch.object(self._svc_monitor.vm_manager, '_create_svc_vm'), patch.object(self._svc_monitor.db, 'service_instance_insert')) as (create_svc_vm, svc_insert): class Vm(object): @property def id(self): return 'ccc' create_svc_vm.return_value = Vm() self._svc_monitor.\ _addmsg_service_instance_service_template(identities) svc_insert.assert_called_with( 'default-domain:default-project:test-instance', { 'vm0-state': 'pending', 'vm0-preference': '0', 'vm0-uuid': 'ccc', 'vm0-vrouter': 'None', 'vm0-name': 'default-domain__default-project__bbb__1' })
def test_vm_instance(self, cassandra_init_mock): logging.debug("init") self._api_client = mock.Mock() arguments = Arguments() with patch.object(logging.handlers, 'RotatingFileHandler'): self._svc_monitor = SvcMonitor(arguments) self._svc_monitor.post_init(self._api_client, arguments) self._svc_monitor.db._svc_si_cf = {} self._svc_monitor.db._svc_vm_cf = mock.Mock() self._svc_monitor._novaclient_get = mock.Mock() identities = { 'service-template': 'default-domain:test:template1', 'service-instance': 'default-domain:test:service1' } tmpl_attr = ServiceTemplateType() tmpl_attr.service_mode = 'in-network-nat' tmpl_attr.service_type = 'firewall' tmpl_attr.image_name = 'test-template' tmpl_attr.service_virtualization_type = 'virtual-machine' template = ServiceTemplate(service_template_properties=tmpl_attr) template.uuid = 'aaa' svc_attr = ServiceInstanceType() svc_attr.left_virtual_network = 'default-project:demo:test' svc_attr.right_virtual_network = 'default-project:admin:public' svc_attr.scale_out = ServiceScaleOutType() service = ServiceInstance('test-instance', service_instance_properties=svc_attr) service.uuid = 'bbb' self._api_client.service_template_read.return_value = template self._api_client.service_instance_read.return_value = service with contextlib.nested( patch.object(self._svc_monitor.vm_manager, '_create_svc_vm'), patch.object(self._svc_monitor.db, 'service_instance_insert')) as (create_svc_vm, svc_insert): class Vm(object): @property def id(self): return 'ccc' create_svc_vm.return_value = Vm() self._svc_monitor.\ _addmsg_service_instance_service_template(identities) svc_insert.assert_called_with( 'default-domain:default-project:test-instance', {'vm0-state': 'pending', 'vm0-preference': '0', 'vm0-uuid': 'ccc', 'vm0-vrouter': 'None', 'vm0-name': 'default-domain__default-project__bbb__1'})
def test_vm_instance(self, uve_mock, cassandra_init_mock): logging.debug("init") self._api_client = mock.Mock() arguments = Arguments() with patch.object(logging.handlers, 'RotatingFileHandler'): self._svc_monitor = SvcMonitor(self._api_client, arguments) self._svc_monitor._svc_si_cf = mock.Mock() self._svc_monitor._svc_vm_cf = mock.Mock() self._svc_monitor._novaclient_get = mock.Mock() identities = { 'service-template': 'default-domain:test:template1', 'service-instance': 'default-domain:test:service1' } tmpl_attr = ServiceTemplateType() tmpl_attr.service_mode = 'in-network-nat' tmpl_attr.service_type = 'firewall' tmpl_attr.image_name = 'test-template' tmpl_attr.service_virtualization_type = 'virtual-machine' template = ServiceTemplate(service_template_properties=tmpl_attr) svc_attr = ServiceInstanceType() svc_attr.left_virtual_network = 'default-project:demo:test' svc_attr.right_virtual_network = 'default-project:admin:public' svc_attr.scale_out = ServiceScaleOutType() service = ServiceInstance('test-instance', service_instance_properties=svc_attr) self._api_client.service_template_read.return_value = template self._api_client.service_instance_read.return_value = service self._svc_monitor.\ _addmsg_service_instance_service_template(identities) expected = { 'instance_name': 'test-instance_1', 'si_fq_str': 'default-domain:default-project:test-instance', 'instance_type': 'virtual-machine' } self._svc_monitor._svc_vm_cf.insert.assert_called_with( mock.ANY, expected)
def _calculate_instance_properties(self, pool, vip): """ ServiceInstance settings - right network: public side, determined by the vip - left network: backend, determined by the pool subnet """ props = ServiceInstanceType() if_list = [] vmi = self._get_virtual_ip_interface(vip) if not vmi: return None vnet_refs = vmi.get_virtual_network_refs() if vnet_refs is None: return None right_virtual_network = ':'.join(vnet_refs[0]['to']) right_ip_address = self._get_interface_address(vmi) if right_ip_address is None: return None right_if = ServiceInstanceInterfaceType( virtual_network=right_virtual_network, ip_address=right_ip_address) if_list.append(right_if) pool_attrs = pool.get_loadbalancer_pool_properties() backnet_id = utils.get_subnet_network_id( self._api, pool_attrs.subnet_id) if backnet_id != vnet_refs[0]['uuid']: try: vnet = self._api.virtual_network_read(id=backnet_id) except NoIdError as ex: LOG.error(ex) return None left_virtual_network = ':'.join(vnet.get_fq_name()) left_if = ServiceInstanceInterfaceType( virtual_network=left_virtual_network) if_list.append(left_if) # set interfaces and ha props.set_interface_list(if_list) props.set_ha_mode('active-standby') scale_out = ServiceScaleOutType(max_instances=2, auto_scale=False) props.set_scale_out(scale_out) return props
def _calculate_instance_properties(self, pool, vip): """ ServiceInstance settings - right network: public side, determined by the vip - left network: backend, determined by the pool subnet """ props = ServiceInstanceType() if_list = [] # Calculate the Right Interface from virtual ip property vmi = VirtualMachineInterfaceSM.get(vip.virtual_machine_interface) if not vmi: return None right_ip_address = self._get_interface_address(vmi) if right_ip_address is None: return None vip_vn = VirtualNetworkSM.get(vmi.virtual_network) if vip_vn is None: return None right_virtual_network = ':'.join(vip_vn.fq_name) right_if = ServiceInstanceInterfaceType( virtual_network=right_virtual_network, ip_address=right_ip_address) if_list.append(right_if) # Calculate the Left Interface from Pool property pool_attrs = pool.params pool_vn_id = self._api.kv_retrieve(pool_attrs['subnet_id']).split()[0] if pool_vn_id != vip_vn.uuid: pool_vn = VirtualNetworkSM.get(pool_vn_id) left_virtual_network = ':'.join(pool_vn.fq_name) left_if = ServiceInstanceInterfaceType( virtual_network=left_virtual_network) if_list.append(left_if) # set interfaces and ha props.set_interface_list(if_list) props.set_ha_mode('active-standby') scale_out = ServiceScaleOutType(max_instances=2, auto_scale=False) props.set_scale_out(scale_out) return props
def test_create_service_instance(self): sas_name = 'sas-1' + self.id() sas_fq_name = ['default-global-system-config', sas_name] sas = ServiceApplianceSet( fq_name=sas_fq_name, parent_type='global-system-config', service_appliance_set_virtualization_type='physical-device') self._vnc_lib.service_appliance_set_create(sas) sa_name = 'sa-1' + self.id() sa_fq_name = ['default-global-system-config', sas_name, sa_name] sa = ServiceAppliance( fq_name=sa_fq_name, parent_type='service-appliance-set', service_appliance_virtualization_type='physical-device') sa.set_service_appliance_properties( KeyValuePairs([ KeyValuePair(key='left-attachment-point', value=self.pi1_0_fq), KeyValuePair(key='right-attachment-point', value=self.pi1_1_fq) ])) attr = ServiceApplianceInterfaceType(interface_type='left') sa.add_physical_interface(self.pi2_0, attr) attr = ServiceApplianceInterfaceType(interface_type='right') sa.add_physical_interface(self.pi2_1, attr) self._vnc_lib.service_appliance_create(sa) tid, td = self.check_trans_info('Service Appliance', 'Create', sa_name, pr_name=self.pr1.name) st_name = 'st-1' + self.id() st_fq_name = ['default-domain', st_name] st = ServiceTemplate(fq_name=st_fq_name) st.set_service_appliance_set(sas) st.set_service_config_managed(False) svc_properties = ServiceTemplateType() svc_properties.set_service_virtualization_type('physical-device') if_type = ServiceTemplateInterfaceType(interface_type='left') svc_properties.add_interface_type(if_type) if_type = ServiceTemplateInterfaceType(interface_type='right') svc_properties.add_interface_type(if_type) st.set_service_template_properties(svc_properties) self._vnc_lib.service_template_create(st) self.check_trans_info(trans_id=tid, trans_descr=td, pr_name=self.pr1.name) si_name = 'si-' + self.id() si_fqn = ['default-domain', 'default-project', si_name] si = ServiceInstance(fq_name=si_fqn) si.fq_name = si_fqn si.add_service_template(st) kvp_array = [] kvp = KeyValuePair("left-svc-vlan", "100") kvp_array.append(kvp) kvp = KeyValuePair("right-svc-vlan", "101") kvp_array.append(kvp) kvp = KeyValuePair("left-svc-asns", "66000,66001") kvp_array.append(kvp) kvp = KeyValuePair("right-svc-asns", "66000,66002") kvp_array.append(kvp) kvps = KeyValuePairs() kvps.set_key_value_pair(kvp_array) si.set_annotations(kvps) props = ServiceInstanceType() props.set_service_virtualization_type('physical-device') props.set_ha_mode("active-standby") si.set_service_instance_properties(props) self._vnc_lib.service_instance_create(si) self.check_trans_info(trans_id=tid, trans_descr=td, pr_name=self.pr1.name) pt_name = 'pt-' + self.id() pt = PortTuple(pt_name, parent_obj=si) pt.add_logical_router(self.lr1) pt.add_logical_router(self.lr2) kvp_array = [] kvp = KeyValuePair("left-lr", self.lr1.uuid) kvp_array.append(kvp) kvp = KeyValuePair("right-lr", self.lr2.uuid) kvp_array.append(kvp) kvps = KeyValuePairs() kvps.set_key_value_pair(kvp_array) pt.set_annotations(kvps) self._vnc_lib.port_tuple_create(pt) self.check_trans_info('Service Instance', 'Create', si_name, pr_name=self.pr1.name) self._vnc_lib.port_tuple_delete(id=pt.uuid) self.check_trans_info('Service Instance', 'Delete', si_name, pr_name=self.pr1.name) self._vnc_lib.service_appliance_delete(fq_name=sa.fq_name) self.check_trans_info('Service Appliance', 'Delete', sa_name, pr_name=self.pr1.name)