def _create_test_instance_with_nic(self, return_server, name): stack_name = '%s_s' % name t = template_format.parse(wp_template_with_nic) template = parser.Template(t) kwargs = { 'KeyName': 'test', 'InstanceType': 'm1.large', 'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861' } stack = parser.Stack(utils.dummy_context(), stack_name, template, environment.Environment(kwargs), stack_id=uuidutils.generate_uuid()) t['Resources']['WebServer']['Properties']['ImageId'] = 'CentOS 5.2' nic = network_interfaces.NetworkInterface('%s_nic' % name, t['Resources']['nic1'], stack) instance = instances.Instance('%s_name' % name, t['Resources']['WebServer'], stack) self.m.StubOutWithMock(nic, 'neutron') nic.neutron().MultipleTimes().AndReturn(FakeNeutron()) self.m.StubOutWithMock(instance, 'nova') instance.nova().MultipleTimes().AndReturn(self.fc) nic.t = nic.stack.resolve_runtime_data(nic.t) instance.t = instance.stack.resolve_runtime_data(instance.t) # need to resolve the template functions server_userdata = nova_utils.build_userdata( instance, instance.t['Properties']['UserData']) instance.mime_string = server_userdata self.m.StubOutWithMock(self.fc.servers, 'create') self.fc.servers.create(image=1, flavor=3, key_name='test', name=utils.PhysName(stack_name, instance.name), security_groups=None, userdata=server_userdata, scheduler_hints=None, meta=None, nics=[{ 'port-id': '64d913c1-bcb1-42d2-8f0a-9593dbcaf251' }], availability_zone=None).AndReturn(return_server) self.m.ReplayAll() # create network interface scheduler.TaskRunner(nic.create)() stack.resources["nic1"] = nic scheduler.TaskRunner(instance.create)() return instance
def _create_test_instance_with_nic(self, return_server, name): stack_name = '%s_s' % name t = template_format.parse(wp_template_with_nic) template = parser.Template(t) kwargs = { 'KeyName': 'test', 'InstanceType': 'm1.large', 'SubnetId': '4156c7a5-e8c4-4aff-a6e1-8f3c7bc83861' } stack = parser.Stack(utils.dummy_context(), stack_name, template, environment.Environment(kwargs), stack_id=str(uuid.uuid4())) image_id = 'CentOS 5.2' t['Resources']['WebServer']['Properties']['ImageId'] = image_id resource_defns = stack.t.resource_definitions(stack) nic = network_interfaces.NetworkInterface('%s_nic' % name, resource_defns['nic1'], stack) instance = instances.Instance('%s_name' % name, resource_defns['WebServer'], stack) metadata = instance.metadata_get() self._mock_get_image_id_success(image_id, 1) self.m.StubOutWithMock(nic, 'neutron') nic.neutron().MultipleTimes().AndReturn(FakeNeutron()) self.m.StubOutWithMock(neutron.NeutronClientPlugin, '_create') neutron.NeutronClientPlugin._create().MultipleTimes().AndReturn( FakeNeutron()) self.m.StubOutWithMock(nova.NovaClientPlugin, '_create') nova.NovaClientPlugin._create().AndReturn(self.fc) # need to resolve the template functions server_userdata = instance.client_plugin().build_userdata( metadata, instance.t['Properties']['UserData'], 'ec2-user') self.m.StubOutWithMock(nova.NovaClientPlugin, 'build_userdata') nova.NovaClientPlugin.build_userdata( metadata, instance.t['Properties']['UserData'], 'ec2-user').AndReturn(server_userdata) self.m.StubOutWithMock(self.fc.servers, 'create') self.fc.servers.create( image=1, flavor=3, key_name='test', name=utils.PhysName(stack_name, instance.name), security_groups=None, userdata=server_userdata, scheduler_hints=None, meta=None, nics=[{ 'port-id': '64d913c1-bcb1-42d2-8f0a-9593dbcaf251' }], availability_zone=None, block_device_mapping=None).AndReturn(return_server) self.m.ReplayAll() # create network interface scheduler.TaskRunner(nic.create)() stack.resources["nic1"] = nic scheduler.TaskRunner(instance.create)() return instance