def test_nova_vm_create_fail(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_security_group(
            'fake-domain:fake-project:default')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
                                       virt_type='virtual-machine',
                                       intf_list=[['management', False],
                                                  ['left', True],
                                                  ['right', False]])
        si = test_utils.create_test_si(name='vm-instance',
                                       count=2,
                                       intf_list=['', 'left-vn', 'right-vn'])

        def nova_oper(resource, oper, proj_name, **kwargs):
            if resource == 'servers' and oper == 'create':
                return None
            else:
                return mock.MagicMock()

        self.nova_mock.oper = nova_oper

        self.vm_manager.create_service(st, si)
        self.log_mock.error.assert_any_call(
            test_utils.AnyStringWith('Nova vm create failed'))
    def test_virtual_machine_exists(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_security_group('fake-domain:fake-project:default')
        test_utils.create_test_virtual_network('fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
            virt_type='virtual-machine',
            intf_list=[['management', False], ['left', True], ['right', False]])
        si = test_utils.create_test_si(name='vm-instance', count=2,
            intf_list=['', 'left-vn', 'right-vn'])

        def nova_oper(resource, oper, proj_name, **kwargs):
            if resource == 'servers' and oper == 'create':
                nova_vm = test_utils.FakeNovaServer(kwargs['name'], kwargs['name'])
                return nova_vm
            else:
                return mock.MagicMock()
        self.nova_mock.oper = nova_oper

        self.mocked_vnc.virtual_machine_create = test_utils.vm_create

        self.vm_manager.create_service(st, si)
        self.log_mock.info.assert_any_call(test_utils.AnyStringWith('Launching VM :'))
        self.log_mock.info.assert_any_call(test_utils.AnyStringWith('Created VM :'))
        self.log_mock.info.assert_any_call(test_utils.AnyStringWith(si.name))
        self.log_mock.reset_mock()

        self.vm_manager.create_service(st, si)
        self.assertTrue(self.log_mock.info.call_count, 1)
    def test_missing_flavor_in_template(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_security_group(
            'fake-domain:fake-project:default')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
                                       virt_type='virtual-machine',
                                       intf_list=[['management', False],
                                                  ['left', True],
                                                  ['right', False]])
        si = test_utils.create_test_si(name='vm-instance',
                                       count=2,
                                       intf_list=['', 'left-vn', 'right-vn'])

        def nova_oper(resource, oper, proj_name, **kwargs):
            if resource == 'flavors' and oper == 'find':
                return None
            else:
                return mock.MagicMock()

        self.nova_mock.oper = nova_oper

        st.params['flavor'] = None
        self.vm_manager.create_service(st, si)
        self.log_mock.error.assert_called_with(
            test_utils.AnyStringWith("Flavor not found"))
    def test_virtual_machine_create(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_security_group(
            'fake-domain:fake-project:default')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
                                       virt_type='virtual-machine',
                                       intf_list=[['management', False],
                                                  ['left', True],
                                                  ['right', False]])
        si = test_utils.create_test_si(name='vm-instance',
                                       count=2,
                                       intf_list=['', 'left-vn', 'right-vn'])

        def nova_oper(resource, oper, proj_name, **kwargs):
            if resource == 'servers' and oper == 'create':
                nova_vm = test_utils.FakeNovaServer('fake-vm-uuid',
                                                    kwargs['name'])
                return nova_vm
            else:
                return mock.MagicMock()

        self.nova_mock.oper = nova_oper

        self.vm_manager.create_service(st, si)
        self.mocked_vnc.virtual_machine_create.assert_any_call(
            test_utils.VMObjMatcher(1))
        self.mocked_vnc.virtual_machine_create.assert_any_call(
            test_utils.VMObjMatcher(2))
        self.assertTrue(si.availability_zone, 'default-availability-zone')
Пример #5
0
    def test_snat_instance_create(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:public-vn')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:fake-vn-uuid')
        test_utils.create_test_security_group(
            'fake-domain:fake-project:default')
        test_utils.create_test_virtual_router('fake-virtual-router')

        st = test_utils.create_test_st(name='snat-template',
                                       virt_type='network-namespace',
                                       intf_list=[['right', True],
                                                  ['left', True]])
        si = test_utils.create_test_si(name='snat-instance',
                                       count=2,
                                       intf_list=['public-vn', 'fake-vn-uuid'])

        self.netns_manager.create_service(st, si)
        self.mocked_vnc.virtual_machine_create.assert_any_call(
            test_utils.VMObjMatcher(1))
        self.mocked_vnc.virtual_machine_create.assert_any_call(
            test_utils.VMObjMatcher(2))
        self.assertEqual(si.vn_info[1]['net-id'],
                         'fake-domain:fake-project:fake-vn-uuid')
Пример #6
0
    def test_vrouter_instance_create(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_security_group(
            'fake-domain:fake-project:default')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:mgmt-vn')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vrouter-template',
                                       virt_type='vrouter-instance',
                                       intf_list=[['management', False],
                                                  ['left', False],
                                                  ['right', False]])
        si = test_utils.create_test_si(
            name='vr-instance',
            count=1,
            vr_id='fake-vr-id',
            intf_list=['mgmt-vn', 'left-vn', 'right-vn'])

        self.vrouter_manager.create_service(st, si)
        self.mocked_vnc.virtual_machine_create.assert_any_call(
            test_utils.VMObjMatcher(1))
        self.mocked_vnc.virtual_router_update.assert_any_call(
            test_utils.VRObjMatcher(['fake-vm-uuid']))
Пример #7
0
    def test_single_vm_port_tuple_create(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_virtual_network('fake-domain:fake-project:public-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:fake-vn-uuid')

        st = test_utils.create_test_st(name='fake-st-uuid',
            intf_list=[['right', True], ['left', True]], version='2')
        si = test_utils.create_test_si(name='fake-si-uuid', count=1,
            intf_list=['public-vn', 'fake-vn-uuid'])
        si.service_template = 'fake-st-uuid'

        pt = test_utils.create_test_port_tuple(
            'fake-domain:fake-project:fake-si-uuid:fake-port-tuple',
            'fake-si-uuid')
        vmi = test_utils.create_test_vmi('fake-domain:fake-project:fake-vmi-uuid-left', pt)
        vmi.params = {}
        vmi.params['service_interface_type'] = 'left'
        vmi = test_utils.create_test_vmi('fake-domain:fake-project:fake-vmi-uuid-right', pt)
        vmi.params = {}
        vmi.params['service_interface_type'] = 'right'

        self.pt_agent.update_port_tuple(pt_id='fake-port-tuple')

        self.mocked_vnc.ref_update.assert_any_call('instance-ip',
            'fake-iip-uuid', 'virtual-machine-interface', 'fake-vmi-uuid-left',
            None, 'ADD')
        self.mocked_vnc.ref_update.assert_any_call('instance-ip',
            'fake-iip-uuid', 'virtual-machine-interface', 'fake-vmi-uuid-right',
            None, 'ADD')
        self.mocked_vnc.ref_update.assert_any_call('service-instance',
            'fake-si-uuid', 'instance-ip', 'fake-iip-uuid', None, 'ADD',
            ServiceInterfaceTag('left'))
        self.mocked_vnc.ref_update.assert_any_call('service-instance',
            'fake-si-uuid', 'instance-ip', 'fake-iip-uuid', None, 'ADD',
            ServiceInterfaceTag('right'))
    def test_vrouter_instance_create(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:mgmt-vn')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(
            name='vrouter-template',
            virt_type='vrouter-instance',
            intf_list=[['management', False], ['left', False],
                       ['right', False]])
        si = test_utils.create_test_si(
            name='vr-instance',
            count=1,
            vr_id='fake-vr-id',
            intf_list=['mgmt-vn', 'left-vn', 'right-vn'])

        self.vrouter_manager.create_service(st, si)
        self.mocked_vnc.virtual_machine_create.assert_any_call(
            test_utils.VMObjMatcher(1))
        self.mocked_vnc.virtual_router_update.assert_any_call(
            test_utils.VRObjMatcher(['fake-vm-uuid']))
    def test_virtual_machine_exists(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_security_group('fake-domain:fake-project:default')
        test_utils.create_test_virtual_network('fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
            virt_type='virtual-machine',
            intf_list=[['management', False], ['left', True], ['right', False]])
        si = test_utils.create_test_si(name='vm-instance', count=2,
            intf_list=['', 'left-vn', 'right-vn'])

        def nova_oper(resource, oper, proj_name, **kwargs):
            if resource == 'servers' and oper == 'create':
                nova_vm = test_utils.FakeNovaServer(kwargs['name'], kwargs['name'])
                return nova_vm
            else:
                return mock.MagicMock()
        self.nova_mock.oper = nova_oper

        self.mocked_vnc.virtual_machine_create = test_utils.vm_create

        self.vm_manager.create_service(st, si)
        self.log_mock.log_info.assert_any_call(test_utils.AnyStringWith('Launching VM :'))
        self.log_mock.log_info.assert_any_call(test_utils.AnyStringWith('Created VM :'))
        self.log_mock.log_info.assert_any_call(test_utils.AnyStringWith(si.name))
        self.log_mock.reset_mock()

        self.vm_manager.create_service(st, si)
        self.assertTrue(self.log_mock.log_info.call_count, 1)
    def test_missing_image_in_template(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_virtual_network('fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
            virt_type='virtual-machine',
            intf_list=[['management', False], ['left', True], ['right', False]])
        si = test_utils.create_test_si(name='vm-instance', count=2,
            intf_list=['', 'left-vn', 'right-vn'])

        st.params['image_name'] = None
        self.vm_manager.create_service(st, si)
        self.log_mock.log_error.assert_called_with("Image not present in %s" % ((':').join(st.fq_name)))
    def test_network_config_validation(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_virtual_network('fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
            virt_type='virtual-machine',
            intf_list=[['management', False], ['left', True], ['right', False]])
        si = test_utils.create_test_si(name='vm-instance', count=2,
            intf_list=['', 'left-vn', 'right-vn'])

        st.params['interface_type'] = []
        self.vm_manager.create_service(st, si)
        self.log_mock.log_notice.assert_called_with("Interface list empty for ST %s SI %s" %
            ((':').join(st.fq_name), (':').join(si.fq_name)))
Пример #12
0
    def test_snat_instance_create(self):
        test_utils.create_test_project("fake-domain:fake-project")
        test_utils.create_test_virtual_network("fake-domain:fake-project:public-vn")
        test_utils.create_test_virtual_network("fake-domain:fake-project:fake-vn-uuid")
        test_utils.create_test_security_group("fake-domain:fake-project:default")

        st = test_utils.create_test_st(
            name="snat-template", virt_type="network-namespace", intf_list=[["right", True], ["left", True]]
        )
        si = test_utils.create_test_si(name="snat-instance", count=2, intf_list=["public-vn", "fake-vn-uuid"])

        self.netns_manager.create_service(st, si)
        self.mocked_vnc.virtual_machine_create.assert_any_call(test_utils.VMObjMatcher(1))
        self.mocked_vnc.virtual_machine_create.assert_any_call(test_utils.VMObjMatcher(2))
        self.assertEqual(si.vn_info[1]["net-id"], "fake-domain:fake-project:fake-vn-uuid")
    def test_missing_image_in_template(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_security_group('fake-domain:fake-project:default')
        test_utils.create_test_virtual_network('fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
            virt_type='virtual-machine',
            intf_list=[['management', False], ['left', True], ['right', False]])
        si = test_utils.create_test_si(name='vm-instance', count=2,
            intf_list=['', 'left-vn', 'right-vn'])

        st.params['image_name'] = None
        self.vm_manager.create_service(st, si)
        self.log_mock.error.assert_called_with("Image not present in %s" % ((':').join(st.fq_name)))
Пример #14
0
    def test_snat_instance_create(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_virtual_network('fake-domain:fake-project:public-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:fake-vn-uuid')
        test_utils.create_test_security_group('fake-domain:fake-project:default')

        st = test_utils.create_test_st(name='snat-template',
            virt_type='network-namespace',
            intf_list=[['right', True], ['left', True]])
        si = test_utils.create_test_si(name='snat-instance', count=2,
            intf_list=['public-vn', 'fake-vn-uuid'])

        self.netns_manager.create_service(st, si)
        self.mocked_vnc.virtual_machine_create.assert_any_call(test_utils.VMObjMatcher(1))
        self.mocked_vnc.virtual_machine_create.assert_any_call(test_utils.VMObjMatcher(2))
        self.assertEqual(si.vn_info[1]['net-id'], 'fake-domain:fake-project:fake-vn-uuid')
    def test_network_config_validation(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_security_group('fake-domain:fake-project:default')
        test_utils.create_test_virtual_network('fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
            virt_type='virtual-machine',
            intf_list=[['management', False], ['left', True], ['right', False]])
        si = test_utils.create_test_si(name='vm-instance', count=2,
            intf_list=['', 'left-vn', 'right-vn'])

        st.params['interface_type'] = []
        self.vm_manager.create_service(st, si)
        self.log_mock.notice.assert_called_with("Interface list empty for ST %s SI %s" %
            ((':').join(st.fq_name), (':').join(si.fq_name)))
    def __create_test_si(self, name=None):
        """
        Create and return a fake/test service-instance(SI).

        The SI is created per schema hierarchy which involves
        creation of test domain, project and service-template.

        """

        # Create test project.
        test_utils.create_test_project('fake-domain:fake-project')

        # Create two VN's for the SI.
        test_utils.create_test_virtual_network(
                             'fake-domain:fake-project:public-vn')
        test_utils.create_test_virtual_network(
                          'fake-domain:fake-project:fake-vn-uuid')

        # Create a service-template.
        st = test_utils.create_test_st(name='fake-st-uuid',
                                       intf_list=[['right', True],
                                                  ['left', True]],
                                       version='2')

        # Create test service-instance.
        if not name:
            name = 'fake-si-uuid'
        si = test_utils.create_test_si(name=name,
                                       count=1,
                                       intf_list=['public-vn',
                                                  'fake-vn-uuid'])

        # Add service-template reference in service-instance.
        si.service_template = 'fake-st-uuid'

        # Mock the update call on this service instance.
        #
        # This being a test service instance, we do not want this
        # SI being updated from config db.
        si.update = mock.MagicMock()

        return si
    def __create_test_si(self, name=None):
        """
        Create and return a fake/test service-instance(SI).

        The SI is created per schema hierarchy which involves
        creation of test domain, project and service-template.

        """

        # Create test project.
        test_utils.create_test_project('fake-domain:fake-project')

        # Create two VN's for the SI.
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:public-vn')
        test_utils.create_test_virtual_network(
            'fake-domain:fake-project:fake-vn-uuid')

        # Create a service-template.
        st = test_utils.create_test_st(name='fake-st-uuid',
                                       intf_list=[['right', True],
                                                  ['left', True]],
                                       version='2')

        # Create test service-instance.
        if not name:
            name = 'fake-si-uuid'
        si = test_utils.create_test_si(name=name,
                                       count=1,
                                       intf_list=['public-vn', 'fake-vn-uuid'])

        # Add service-template reference in service-instance.
        si.service_template = 'fake-st-uuid'

        # Mock the update call on this service instance.
        #
        # This being a test service instance, we do not want this
        # SI being updated from config db.
        si.update = mock.MagicMock()

        return si
    def test_missing_flavor_in_template(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_virtual_network('fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
            virt_type='virtual-machine',
            intf_list=[['management', False], ['left', True], ['right', False]])
        si = test_utils.create_test_si(name='vm-instance', count=2,
            intf_list=['', 'left-vn', 'right-vn'])

        def nova_oper(resource, oper, proj_name, **kwargs):
            if resource == 'flavors' and oper == 'find':
                return None
            else:
                return mock.MagicMock()
        self.nova_mock.oper = nova_oper

        st.params['flavor'] = None
        self.vm_manager.create_service(st, si)
        self.log_mock.log_error.assert_called_with(test_utils.AnyStringWith("Flavor not found"))
    def test_nova_vm_create_fail(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_security_group('fake-domain:fake-project:default')
        test_utils.create_test_virtual_network('fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
            virt_type='virtual-machine',
            intf_list=[['management', False], ['left', True], ['right', False]])
        si = test_utils.create_test_si(name='vm-instance', count=2,
            intf_list=['', 'left-vn', 'right-vn'])

        def nova_oper(resource, oper, proj_name, **kwargs):
            if resource == 'servers' and oper == 'create':
                return None
            else:
                return mock.MagicMock()
        self.nova_mock.oper = nova_oper

        self.vm_manager.create_service(st, si)
        self.log_mock.log_error.assert_any_call(test_utils.AnyStringWith('Nova vm create failed'))
    def test_missing_image_in_nova(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_security_group('fake-domain:fake-project:default')
        test_utils.create_test_virtual_network('fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
            virt_type='virtual-machine',
            intf_list=[['management', False], ['left', True], ['right', False]])
        si = test_utils.create_test_si(name='vm-instance', count=2,
            intf_list=['', 'left-vn', 'right-vn'])

        def nova_oper(resource, oper, proj_name, **kwargs):
            if resource == 'images' and oper == 'find':
                return None
            else:
                return mock.MagicMock()
        self.nova_mock.oper = nova_oper

        self.vm_manager.create_service(st, si)
        self.log_mock.log_error.assert_called_with("Image not found %s" % si.image)
    def test_availability_zone_setting(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_virtual_network('fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
            virt_type='virtual-machine',
            intf_list=[['management', False], ['left', True], ['right', False]])
        si = test_utils.create_test_si(name='vm-instance', count=2,
            intf_list=['', 'left-vn', 'right-vn'])

        def nova_oper(resource, oper, proj_name, **kwargs):
            if resource == 'servers' and oper == 'create':
                nova_vm = test_utils.FakeNovaServer('fake-vm-uuid', kwargs['name'])
                return nova_vm
            else:
                return mock.MagicMock()
        self.nova_mock.oper = nova_oper

        st.params['availability_zone_enable'] = True
        si.params['availability_zone'] = 'test-availability-zone'
        self.vm_manager.create_service(st, si)
        self.assertTrue(si.availability_zone, 'test-availability-zone') 
    def test_virtual_machine_static_routes(self):
        test_utils.create_test_project('fake-domain:fake-project')
        test_utils.create_test_security_group('fake-domain:fake-project:default')
        test_utils.create_test_virtual_network('fake-domain:fake-project:left-vn')
        test_utils.create_test_virtual_network('fake-domain:fake-project:right-vn')

        st = test_utils.create_test_st(name='vm-template',
            virt_type='virtual-machine',
            intf_list=[['management', False], ['left', True, True], ['right', False]])
        si = test_utils.create_test_si(name='vm-instance', count=2,
            intf_list=['', 'left-vn', 'right-vn'])

        def nova_oper(resource, oper, proj_name, **kwargs):
            if resource == 'servers' and oper == 'create':
                nova_vm = test_utils.FakeNovaServer('fake-vm-uuid', kwargs['name'])
                return nova_vm
            else:
                return mock.MagicMock()
        self.nova_mock.oper = nova_oper

        self.vm_manager.create_service(st, si)
        self.mocked_vnc.virtual_machine_create.assert_any_call(test_utils.VMObjMatcher(1))
        self.mocked_vnc.virtual_machine_create.assert_any_call(test_utils.VMObjMatcher(2))