def test_build_network_config(self): net = utils.get_test_network_info(1, legacy_model=False) config = pxe.build_network_config(net) self.assertIn('eth0', config) self.assertNotIn('eth1', config) net = utils.get_test_network_info(2, legacy_model=False) config = pxe.build_network_config(net) self.assertIn('eth0', config) self.assertIn('eth1', config)
def test_build_network_config(self): net = utils.get_test_network_info(1) config = pxe.build_network_config(net) self.assertIn('eth0', config) self.assertNotIn('eth1', config) net = utils.get_test_network_info(2) config = pxe.build_network_config(net) self.assertIn('eth0', config) self.assertIn('eth1', config)
def test_inject_into_image(self): # NOTE(deva): we could also test this method by stubbing # nova.virt.disk.api._inject_*_into_fs self._create_node() files = [] self.instance['hostname'] = 'fake hostname' files.append(('/etc/hostname', 'fake hostname')) self.instance['key_data'] = 'fake ssh key' net_info = utils.get_test_network_info(1) net = pxe.build_network_config(net_info) admin_password = '******' self.mox.StubOutWithMock(disk_api, 'inject_data') disk_api.inject_data( admin_password=admin_password, image=pxe.get_image_file_path(self.instance), key='fake ssh key', metadata=None, partition=None, net=net, files=files, # this is what we're really testing ).AndReturn(True) self.mox.ReplayAll() self.driver._inject_into_image( self.context, self.node, self.instance, network_info=net_info, admin_password=admin_password, injected_files=None) self.mox.VerifyAll()
def test_build_network_config(self): net = utils.get_test_network_info(1) config = pxe.build_network_config(net) self.assertIn('eth0', config) self.assertNotIn('eth1', config) self.assertIn('hwaddress ether fake', config) self.assertNotIn('hwaddress ether aa:bb:cc:dd', config) net[0][1]['mac'] = 'aa:bb:cc:dd' config = pxe.build_network_config(net) self.assertIn('hwaddress ether aa:bb:cc:dd', config) net = utils.get_test_network_info(2) config = pxe.build_network_config(net) self.assertIn('eth0', config) self.assertIn('eth1', config)
def test_build_network_config_dhcp(self): self.flags(net_config_template="$pybasedir/nova/virt/baremetal/" "net-dhcp.ubuntu.template", group="baremetal") net = utils.get_test_network_info() net[0][1]["ips"][0]["ip"] = "1.2.3.4" config = pxe.build_network_config(net) self.assertIn("iface eth0 inet dhcp", config) self.assertNotIn("address 1.2.3.4", config)
def test_build_network_config_static_parameters(self): self.flags(use_ipv6=True) self.flags( net_config_template='$pybasedir/nova/virt/baremetal/' 'net-static.ubuntu.template', group='baremetal' ) net = utils.get_test_network_info() net[0]['network']['subnets'][0]['cidr'] = '10.1.1.0/24' net[0]['network']['subnets'][0]['gateway']['address'] = '10.1.1.1' net[0]['network']['subnets'][0]['dns'][0]['address'] = '10.1.1.2' net[0]['network']['subnets'][0]['dns'][1]['address'] = '10.1.1.3' net[0]['network']['subnets'][1]['cidr'] = 'fc00::/7' net[0]['network']['subnets'][1]['ips'][0]['address'] = 'fc00::1' net[0]['network']['subnets'][1]['gateway']['address'] = 'fc00::2' config = pxe.build_network_config(net) self.assertIn('iface eth0 inet static', config) self.assertIn('gateway 10.1.1.1', config) self.assertIn('dns-nameservers 10.1.1.2 10.1.1.3', config) self.assertIn('iface eth0 inet6 static', config) self.assertIn('address fc00::1', config) self.assertIn('netmask 7', config) self.assertIn('gateway fc00::2', config)
def test_build_network_config_static_parameters(self): self.flags(use_ipv6=True) self.flags(net_config_template='$pybasedir/nova/virt/baremetal/' 'net-static.ubuntu.template', group='baremetal') net = utils.get_test_network_info() net[0]['network']['subnets'][0]['cidr'] = '10.1.1.0/24' net[0]['network']['subnets'][0]['gateway']['address'] = '10.1.1.1' net[0]['network']['subnets'][0]['dns'][0]['address'] = '10.1.1.2' net[0]['network']['subnets'][0]['dns'][1]['address'] = '10.1.1.3' net[0]['network']['subnets'][1]['cidr'] = 'fc00::/7' net[0]['network']['subnets'][1]['ips'][0]['address'] = 'fc00::1' net[0]['network']['subnets'][1]['gateway']['address'] = 'fc00::2' config = pxe.build_network_config(net) self.assertIn('iface eth0 inet static', config) self.assertIn('gateway 10.1.1.1', config) self.assertIn('dns-nameservers 10.1.1.2 10.1.1.3', config) self.assertIn('iface eth0 inet6 static', config) self.assertIn('address fc00::1', config) self.assertIn('netmask 7', config) self.assertIn('gateway fc00::2', config)
def test_inject_into_image(self): # NOTE(deva): we could also test this method by stubbing # nova.virt.disk.api._inject_*_into_fs self._create_node() files = [] self.instance['hostname'] = 'fake hostname' files.append(('/etc/hostname', 'fake hostname')) self.instance['key_data'] = 'fake ssh key' net_info = utils.get_test_network_info(1) net = pxe.build_network_config(net_info) admin_password = '******' self.mox.StubOutWithMock(disk_api, 'inject_data') disk_api.inject_data( admin_password=admin_password, image=pxe.get_image_file_path(self.instance), key='fake ssh key', metadata=None, partition=None, net=net, files=files, # this is what we're really testing ).AndReturn(True) self.mox.ReplayAll() self.driver._inject_into_image(self.context, self.node, self.instance, network_info=net_info, admin_password=admin_password, injected_files=None) self.mox.VerifyAll()
def test_build_network_config_static_parameters(self): self.flags(use_ipv6=True) self.flags( net_config_template="$pybasedir/nova/virt/baremetal/" "net-static.ubuntu.template", group="baremetal" ) net = utils.get_test_network_info() net[0]["network"]["subnets"][0]["cidr"] = "10.1.1.0/24" net[0]["network"]["subnets"][0]["gateway"]["address"] = "10.1.1.1" net[0]["network"]["subnets"][0]["dns"][0]["address"] = "10.1.1.2" net[0]["network"]["subnets"][0]["dns"][1]["address"] = "10.1.1.3" net[0]["network"]["subnets"][1]["cidr"] = "fc00::/7" net[0]["network"]["subnets"][1]["ips"][0]["address"] = "fc00::1" net[0]["network"]["subnets"][1]["gateway"]["address"] = "fc00::2" config = pxe.build_network_config(net) self.assertIn("iface eth0 inet static", config) self.assertIn("gateway 10.1.1.1", config) self.assertIn("dns-nameservers 10.1.1.2 10.1.1.3", config) self.assertIn("iface eth0 inet6 static", config) self.assertIn("address fc00::1", config) self.assertIn("netmask 7", config) self.assertIn("gateway fc00::2", config)
def test_build_network_config_static(self): self.flags( net_config_template='$pybasedir/nova/virt/baremetal/' 'net-static.ubuntu.template', group='baremetal', ) net = utils.get_test_network_info() net[0]['network']['subnets'][0]['ips'][0]['address'] = '1.2.3.4' config = pxe.build_network_config(net) self.assertIn('iface eth0 inet static', config) self.assertIn('address 1.2.3.4', config)
def test_build_network_config_dhcp(self): self.flags( net_config_template='$pybasedir/nova/virt/baremetal/' 'net-dhcp.ubuntu.template', group='baremetal', ) net = utils.get_test_network_info(legacy_model=False) net[0]['network']['subnets'][0]['ips'][0]['address'] = '1.2.3.4' config = pxe.build_network_config(net) self.assertIn('iface eth0 inet dhcp', config) self.assertNotIn('address 1.2.3.4', config)
def test_inject_into_image(self): # NOTE(deva): we could also test this method by stubbing # nova.virt.disk.api._inject_*_into_fs self._create_node() files = [] self.instance["hostname"] = "fake hostname" files.append(("/etc/hostname", "fake hostname")) self.instance["key_data"] = "fake ssh key" net_info = utils.get_test_network_info(1) net = pxe.build_network_config(net_info) admin_password = "******" self.mox.StubOutWithMock(os.path, "exists") os.path.exists(mox.IgnoreArg()).AndReturn(True) self.mox.StubOutWithMock(disk_api, "inject_data") disk_api.inject_data( admin_password=admin_password, image=pxe.get_image_file_path(self.instance), key="fake ssh key", metadata=None, partition=None, net=net, files=files, # this is what we're really testing ).AndReturn(True) self.mox.ReplayAll() self.driver._inject_into_image( self.context, self.node, self.instance, network_info=net_info, admin_password=admin_password, injected_files=None, ) self.mox.VerifyAll()