def generator(cls): marker_one = "%s-one" % cls.__name__.lower() ignition_file = "inte-%s.yaml" % marker_one gen_one = generator.Generator(api_uri=cls.api_uri, profile_id="id-%s" % marker_one, name="name-%s" % marker_one, ignition_id=ignition_file, selector={"mac": cls.mac_one}, matchbox_path=cls.test_matchbox_path) gen_one.dumps() marker_two = "%s-two" % cls.__name__.lower() ignition_file = "inte-%s.yaml" % marker_two gen_one = generator.Generator(api_uri=cls.api_uri, profile_id="id-%s" % marker_two, name="name-%s" % marker_two, ignition_id=ignition_file, selector={"mac": cls.mac_two}, matchbox_path=cls.test_matchbox_path) gen_one.dumps() marker_three = "%s-three" % cls.__name__.lower() ignition_file = "inte-testbootconfigselectors-default.yaml" gen_one = generator.Generator(api_uri=cls.api_uri, profile_id="id-%s" % marker_three, name="name-%s" % marker_three, ignition_id=ignition_file, matchbox_path=cls.test_matchbox_path) gen_one.dumps()
def test_00(self): marker = "euid-%s-%s" % (TestKVMDiscoveryClient.__name__.lower(), self.test_00.__name__) gen = generator.Generator( api_uri=self.api_uri, profile_id="%s" % marker, name="%s" % marker, ignition_id="%s.yaml" % marker, matchbox_path=self.test_matchbox_path ) gen.dumps() self.clean_up_virtual_machine(marker) interfaces = {} try: virt_install = self.create_virtual_machine(marker, 1) self.virsh(virt_install, assertion=True, v=self.dev_null) for i in range(60): interfaces = self.fetch_discovery_interfaces() if len(interfaces) > 0: break time.sleep(self.testing_sleep_seconds) # Just one machine self.assertEqual(len(interfaces), 1) for i in interfaces: self.assertEqual(i["name"], "eth0") self.assertEqual(i["netmask"], 16) self.assertEqual(i["ipv4"][:9], '172.20.0.') self.assertEqual(len(i["mac"]), 17) self.assertTrue(i["as_boot"]) self.write_ending(marker) finally: self.clean_up_virtual_machine(marker)
def test_05_ipxe_selector(self): mac = "00:00:00:00:00:00" marker = "%s-%s" % (TestAPIGunicorn.__name__.lower(), self.test_05_ipxe_selector.__name__) ignition_file = "inte-%s.yaml" % marker gen = generator.Generator( api_uri=ec.api_uri, profile_id="id-%s" % marker, name="name-%s" % marker, ignition_id=ignition_file, selector={"mac": mac}, matchbox_path=self.test_matchbox_path ) gen.dumps() r = requests.get("%s/ipxe" % ec.api_uri) self.assertEqual(200, r.status_code) request = requests.get("%s/ipxe?mac=%s" % (ec.api_uri, mac)) response_body = request.content.decode() response_code = request.status_code request.close() expect = "#!ipxe\n" \ "kernel %s/assets/coreos/serve/coreos_production_pxe.vmlinuz " \ "console=ttyS0 console=ttyS1 " \ "coreos.config.url=%s/ignition?uuid=${uuid}&mac=${net0/mac:hexhyp} " \ "coreos.first_boot coreos.oem.id=pxe\n" \ "initrd %s/assets/coreos/serve/coreos_production_pxe_image.cpio.gz \n" \ "boot\n" % (gen.profile.api_uri, gen.profile.api_uri, gen.profile.api_uri) self.maxDiff = None self.assertEqual(expect, response_body) self.assertEqual(200, response_code)
def test_02(self): marker = "euid-%s-%s" % (TestKVMDiscoveryClient.__name__.lower(), self.test_02.__name__) gen = generator.Generator( api_uri=self.api_uri, profile_id="%s" % marker, name="%s" % marker, ignition_id="%s.yaml" % marker, matchbox_path=self.test_matchbox_path, extra_metadata={ "lldp_image_url": self.ec.lldp_image_url, "etc_hosts": self.ec.etc_hosts, } ) gen.dumps() destroy, undefine = ["virsh", "destroy", "%s" % marker], ["virsh", "undefine", "%s" % marker] self.virsh(destroy, v=self.dev_null), self.virsh(undefine, v=self.dev_null) interfaces = [] try: virt_install = [ "virt-install", "--name", "%s" % marker, "--network=bridge:rack0,model=virtio", "--memory=2048", "--vcpus=%d" % self.get_optimized_cpu(1), "--pxe", "--disk", "none", "--os-type=linux", "--os-variant=generic", "--noautoconsole", "--boot=network" ] self.virsh(virt_install, assertion=True, v=self.dev_null) for i in range(60): interfaces = self.fetch_discovery_interfaces() if len(interfaces) > 0: break time.sleep(self.testing_sleep_seconds) self.assertEqual(len(interfaces), 1) for interface in interfaces: self.assertIsNotNone(interface["chassis_name"]) self.assertEqual(interface["name"], "eth0") self.assertEqual(interface["netmask"], 16) self.assertEqual(interface["ipv4"][:9], '172.20.0.') self.assertEqual(len(interface["mac"]), 17) self.assertTrue(interface["as_boot"]) self.write_ending(marker) finally: self.virsh(destroy) self.virsh(undefine)
def generator(cls): marker = "%s" % cls.__name__.lower() ignition_file = "inte-%s.yaml" % marker cls.gen = generator.Generator(api_uri=cls.api_uri, profile_id="id-%s" % marker, name="name-%s" % marker, ignition_id=ignition_file, selector={"mac": cls.mac}, matchbox_path=cls.test_matchbox_path) cls.gen.dumps()
def test_04(self): marker = "euid-%s-%s" % (TestKVMDiscoveryClient.__name__.lower(), self.test_04.__name__) gen = generator.Generator( api_uri=self.api_uri, profile_id="%s" % marker, name="%s" % marker, ignition_id="%s.yaml" % marker, matchbox_path=self.test_matchbox_path, extra_metadata={ "lldp_image_url": self.ec.lldp_image_url, "etc_hosts": self.ec.etc_hosts, } ) gen.dumps() destroy, undefine = ["virsh", "destroy", "%s" % marker], ["virsh", "undefine", "%s" % marker] self.virsh(destroy, v=self.dev_null), self.virsh(undefine, v=self.dev_null) try: virt_install = [ "virt-install", "--name", "%s" % marker, "--network=bridge:rack0,model=virtio", "--memory=1024", "--vcpus=%d" % self.get_optimized_cpu(1), "--pxe", "--disk", "none", "--os-type=linux", "--os-variant=generic", "--noautoconsole", "--boot=network" ] self.virsh(virt_install, assertion=True, v=self.dev_null) disco_data = dict() for i in range(60): disco_data = self.fetch_discovery() if disco_data and len(disco_data) == 1: break time.sleep(self.testing_sleep_seconds) self.assertEqual(1, len(disco_data)) lines = self.fetch_discovery_ignition_journal(disco_data[0]["boot-info"]["uuid"]) self.assertIs(type(lines), list) self.assertTrue(len(lines) > 0) self.write_ending(marker) finally: self.virsh(destroy) self.virsh(undefine)
def generator(cls): marker = "%s" % cls.__name__.lower() ignition_file = "inte-%s.yaml" % marker try: cls.gen = generator.Generator(api_uri=cls.api_uri, profile_id="id-%s" % marker, name="name-%s" % marker, ignition_id=ignition_file, matchbox_path=cls.test_matchbox_path) except IOError: print( "\nWARNING %s override %s in %s\n" % (cls.__name__, generator.GenerateCommon._raise_enof, Warning)) sys.stderr.flush() with IOErrorToWarning(): cls.gen = generator.Generator( api_uri=cls.api_uri, profile_id="id-%s" % marker, name="name-%s" % marker, ignition_id=ignition_file, matchbox_path=cls.test_matchbox_path) cls.gen.dumps()
def test_05_ipxe_selector(self): mac = "00:00:00:00:00:00" marker = "%s-%s" % (TestAPI.__name__.lower(), self.test_05_ipxe_selector.__name__) ignition_file = "inte-%s.yaml" % marker gen = generator.Generator(api_uri=ec.api_uri, profile_id="id-%s" % marker, name="name-%s" % marker, ignition_id=ignition_file, selector={"mac": mac}, matchbox_path=self.test_matchbox_path) gen.dumps() result = self.app.get('/ipxe?mac=%s' % mac) expect = "#!ipxe\n" \ "kernel %s/assets/coreos/serve/coreos_production_pxe.vmlinuz " \ "console=ttyS0 console=ttyS1 coreos.config.url=%s/ignition?uuid=${uuid}&mac=${net0/mac:hexhyp} " \ "coreos.first_boot coreos.oem.id=pxe\n" \ "initrd %s/assets/coreos/serve/coreos_production_pxe_image.cpio.gz \n" \ "boot\n" % (gen.profile.api_uri, gen.profile.api_uri, gen.profile.api_uri) expect = str.encode(expect) self.assertEqual(expect, result.data) self.assertEqual(200, result.status_code)
def test_01(self): nb_node = 3 marker = "euid-%s-%s" % (TestKVMDiscoveryClient.__name__.lower(), self.test_01.__name__) gen = generator.Generator( api_uri=self.api_uri, profile_id="%s" % marker, name="%s" % marker, ignition_id="%s.yaml" % marker, matchbox_path=self.test_matchbox_path ) gen.dumps() interfaces = {} try: for i in range(nb_node): machine_marker = "%s-%d" % (marker, i) destroy, undefine = ["virsh", "destroy", "%s" % machine_marker], \ ["virsh", "undefine", "%s" % machine_marker] self.virsh(destroy, v=self.dev_null), self.virsh(undefine, v=self.dev_null) virt_install = [ "virt-install", "--name", "%s" % machine_marker, "--network=bridge:rack0,model=virtio", "--memory=1024", "--vcpus=%d" % self.get_optimized_cpu(nb_node), "--pxe", "--disk", "none", "--os-type=linux", "--os-variant=generic", "--noautoconsole", "--boot=network" ] self.virsh(virt_install, assertion=True, v=self.dev_null) time.sleep(self.testing_sleep_seconds) # KVM fail to associate nic for i in range(60): interfaces = self.fetch_discovery_interfaces() if len(interfaces) == nb_node: break time.sleep(self.testing_sleep_seconds) # Several machines self.assertEqual(len(interfaces), nb_node) for i in interfaces: self.assertEqual(i["name"], "eth0") self.assertEqual(i["netmask"], 16) self.assertEqual(i["ipv4"][:9], '172.20.0.') self.assertEqual(len(i["mac"]), 17) self.assertTrue(i["as_boot"]) self.write_ending(marker) finally: for i in range(nb_node): machine_marker = "%s-%d" % (marker, i) destroy, undefine = ["virsh", "destroy", "%s" % machine_marker], \ ["virsh", "undefine", "%s" % machine_marker] self.virsh(destroy) self.virsh(undefine)
def test_06(self): nb_node = 3 marker = "euid-%s-%s" % (TestKVMDiscoveryClient.__name__.lower(), self.test_06.__name__) gen = generator.Generator( api_uri=self.api_uri, profile_id="%s" % marker, name="%s" % marker, ignition_id="%s.yaml" % marker, matchbox_path=self.test_matchbox_path, extra_metadata={ "lldp_image_url": self.ec.lldp_image_url, "etc_hosts": self.ec.etc_hosts, } ) gen.dumps() interfaces = {} try: for i in range(nb_node): machine_marker = "%s-%d" % (marker, i) destroy, undefine = ["virsh", "destroy", "%s" % machine_marker], \ ["virsh", "undefine", "%s" % machine_marker] self.virsh(destroy, v=self.dev_null), self.virsh(undefine, v=self.dev_null) virt_install = [ "virt-install", "--name", "%s" % machine_marker, "--network=bridge:rack0,model=virtio", "--network=bridge:rack0,model=virtio", "--network=bridge:rack0,model=virtio", "--network=bridge:rack0,model=virtio", "--memory=1024", "--vcpus=%d" % self.get_optimized_cpu(nb_node), "--pxe", "--disk", "none", "--os-type=linux", "--os-variant=generic", "--noautoconsole", "--boot=network" ] self.virsh(virt_install, assertion=True, v=self.dev_null) time.sleep(self.testing_sleep_seconds) # KVM fail to associate nic for i in range(60): interfaces = self.fetch_discovery_interfaces() if len(interfaces) == nb_node * 4: break time.sleep(self.testing_sleep_seconds) # Just one machine but with 4 interfaces self.assertEqual(len(interfaces), 4 * nb_node) as_boot = 0 as_not_boot = 0 for i in interfaces: self.assertEqual(i["netmask"], 16) self.assertEqual(i["ipv4"][:9], '172.20.0.') self.assertEqual(len(i["mac"]), 17) try: self.assertTrue(i["as_boot"]) as_boot += 1 except AssertionError: self.assertFalse(i["as_boot"]) as_not_boot += 1 self.assertEqual(as_boot, nb_node) self.assertEqual(as_not_boot, nb_node * 3) self.write_ending(marker) finally: for i in range(nb_node): machine_marker = "%s-%d" % (marker, i) destroy, undefine = ["virsh", "destroy", "%s" % machine_marker], \ ["virsh", "undefine", "%s" % machine_marker] self.virsh(destroy) self.virsh(undefine)