コード例 #1
0
 def get_lb_template(self):
     st = ServiceTemplateSM.get(self._lb_template)
     template_obj = ServiceTemplate(st.name,
                                    parent_type='domain',
                                    fq_name=st.fq_name)
     template_obj.uuid = st.uuid
     return template_obj
コード例 #2
0
    def test_create_pool(self):
        tenant_id = _uuid()
        pool_id = _uuid()
        vip_id = _uuid()
        subnet_id = _uuid()

        api = self.api_server

        project = Project(name='test')
        project.uuid = tenant_id
        template = ServiceTemplate('lb-test', project)
        template.uuid = _uuid()

        pool_attrs = LoadbalancerPoolType()
        pool_attrs.subnet_id = subnet_id
        pool = LoadbalancerPool(
            pool_id, project, loadbalancer_pool_properties=pool_attrs)
        pool.uuid = pool_id

        vip_attrs = VirtualIpType()
        vip_attrs.subnet_id = subnet_id
        vip_attrs.address = '127.0.0.1'
        vip = VirtualIp(vip_id, project, virtual_ip_properties=vip_attrs)
        vip.uuid = vip_id
        vip.set_loadbalancer_pool(pool)

        vnet = VirtualNetwork('test', project)
        vnet.uuid = _uuid()

        vmi = VirtualMachineInterface(vip_id, project)
        vmi.uuid = _uuid()
        vmi.set_virtual_network(vnet)
        iip = InstanceIp(vip_id, instance_ip_address='127.0.0.1')
        iip.uuid = _uuid()
        iip.set_virtual_machine_interface(vmi)

        iip_refs = [
            {'to': iip.get_fq_name(), 'uuid': iip.uuid}
        ]
        vmi.get_instance_ip_back_refs = mock.Mock()
        vmi.get_instance_ip_back_refs.return_value = iip_refs

        vip.set_virtual_machine_interface(vmi)

        api.virtual_service_template_read = template
        api.loadbalancer_pool_read.return_value = pool
        api.virtual_ip_read.return_value = vip
        api.kv_retrieve.return_value = '%s %s' % (vnet.uuid, subnet_id)
        api.virtual_machine_interface_read.return_value = vmi
        api.instance_ip_read.return_value = iip
        api.service_instance_read.side_effect = NoIdError('404')

        context = {}
        pool_data = {
            'id': pool_id,
            'vip_id': vip_id
        }
        self.driver.create_pool(context, pool_data)
        api.service_instance_create.assert_called_with(mock.ANY)
コード例 #3
0
    def test_create_pool(self):
        tenant_id = _uuid()
        pool_id = _uuid()
        vip_id = _uuid()
        subnet_id = _uuid()

        api = self.api_server

        project = Project(name='test')
        project.uuid = tenant_id
        template = ServiceTemplate('lb-test', project)
        template.uuid = _uuid()

        pool_attrs = LoadbalancerPoolType()
        pool_attrs.subnet_id = subnet_id
        pool = LoadbalancerPool(
            pool_id, project, loadbalancer_pool_properties=pool_attrs)
        pool.uuid = pool_id

        vip_attrs = VirtualIpType()
        vip_attrs.subnet_id = subnet_id
        vip_attrs.address = '127.0.0.1'
        vip = VirtualIp(vip_id, project, virtual_ip_properties=vip_attrs)
        vip.uuid = vip_id
        vip.set_loadbalancer_pool(pool)

        vnet = VirtualNetwork('test', project)
        vnet.uuid = _uuid()

        vmi = VirtualMachineInterface(vip_id, project)
        vmi.uuid = _uuid()
        vmi.set_virtual_network(vnet)
        iip = InstanceIp(vip_id, instance_ip_address='127.0.0.1')
        iip.uuid = _uuid()
        iip.set_virtual_machine_interface(vmi)

        iip_refs = [
            {'to': iip.get_fq_name(), 'uuid': iip.uuid}
        ]
        vmi.get_instance_ip_back_refs = mock.Mock()
        vmi.get_instance_ip_back_refs.return_value = iip_refs

        vip.set_virtual_machine_interface(vmi)

        api.virtual_service_template_read = template
        api.loadbalancer_pool_read.return_value = pool
        api.virtual_ip_read.return_value = vip
        api.kv_retrieve.return_value = '%s %s' % (vnet.uuid, subnet_id)
        api.virtual_machine_interface_read.return_value = vmi
        api.instance_ip_read.return_value = iip
        api.service_instance_read.side_effect = NoIdError('404')

        context = {}
        pool_data = {
            'id': pool_id,
            'vip_id': vip_id
        }
        self.driver.create_pool(context, pool_data)
        api.service_instance_create.assert_called_with(mock.ANY)
コード例 #4
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'
                    })
コード例 #5
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'})
コード例 #6
0
    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)
コード例 #7
0
 def get_lb_template(self):
     st = ServiceTemplateSM.get(self._lb_template)
     template_obj = ServiceTemplate(st.name, parent_type = 'domain',
                                    fq_name = st.fq_name)
     template_obj.uuid = st.uuid
     return template_obj