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)
示例#3
0
    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 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)