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 _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_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)