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_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_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')
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_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']))
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')
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)))
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.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_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.log_notice.assert_called_with("Interface list empty for ST %s SI %s" % ((':').join(st.fq_name), (':').join(si.fq_name)))
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']))
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 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_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))
def test_availability_zone_setting(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 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')