Example #1
0
    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()
Example #2
0
    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(self):
        marker = "euid-%s-%s" % (TestKVMDiscoveryClient.__name__.lower(),
                                 self.test_05.__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",
                "--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)

            for i in range(60):
                interfaces = self.fetch_discovery_interfaces()
                if len(interfaces) > 0:
                    break
                time.sleep(self.testing_sleep_seconds)

            # Just one machine but with 2 interfaces
            self.assertEqual(len(interfaces), 2)
            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"])
                except AssertionError:
                    self.assertFalse(i["as_boot"])
                try:
                    self.assertEqual(i["name"], "eth0")
                except AssertionError:
                    self.assertEqual(i["name"], "eth1")

            self.write_ending(marker)
        finally:
            self.virsh(destroy)
            self.virsh(undefine)
    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)
Example #6
0
 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)
Example #8
0
    def produce_matchbox_data(self,
                              marker: str,
                              i: int,
                              m: dict,
                              automatic_name: str,
                              update_extra_metadata=None):
        fqdn = automatic_name
        try:
            if m["fqdn"]:
                fqdn = m["fqdn"]
        except KeyError as e:
            logger.warning("%s for %s" % (e, m["mac"]))

        etc_hosts = [k for k in EC.etc_hosts]
        dns_attr = self.get_dns_attr(fqdn)
        etc_hosts.append("127.0.1.1 %s %s" % (fqdn, dns_attr["shortname"]))
        cni_attr = self._cni_ipam(m["cidrv4"], m["gateway"])
        extra_metadata = {
            "etc_hosts":
            etc_hosts,
            # Etcd
            "etcd_name":
            m["ipv4"],
            "kubernetes_etcd_initial_cluster":
            self.kubernetes_etcd_initial_cluster,
            "vault_etcd_initial_cluster":
            self.vault_etcd_initial_cluster,
            "fleet_etcd_initial_cluster":
            self.fleet_etcd_initial_cluster,
            "kubernetes_etcd_initial_advertise_peer_urls":
            "https://%s:%d" % (m["ipv4"], EC.kubernetes_etcd_peer_port),
            "vault_etcd_initial_advertise_peer_urls":
            "https://%s:%d" % (m["ipv4"], EC.vault_etcd_peer_port),
            "fleet_etcd_initial_advertise_peer_urls":
            "https://%s:%d" % (m["ipv4"], EC.fleet_etcd_peer_port),
            "kubernetes_etcd_member_client_uri_list":
            ",".join(self.kubernetes_etcd_member_client_uri_list),
            "vault_etcd_member_client_uri_list":
            ",".join(self.vault_etcd_member_client_uri_list),
            "fleet_etcd_member_client_uri_list":
            ",".join(self.fleet_etcd_member_client_uri_list),
            "kubernetes_etcd_data_dir":
            EC.kubernetes_etcd_data_dir,
            "vault_etcd_data_dir":
            EC.vault_etcd_data_dir,
            "fleet_etcd_data_dir":
            EC.fleet_etcd_data_dir,
            "kubernetes_etcd_client_port":
            EC.kubernetes_etcd_client_port,
            "vault_etcd_client_port":
            EC.vault_etcd_client_port,
            "fleet_etcd_client_port":
            EC.fleet_etcd_client_port,
            "kubernetes_etcd_advertise_client_urls":
            "https://%s:%d" % (m["ipv4"], EC.kubernetes_etcd_client_port),
            "vault_etcd_advertise_client_urls":
            "https://%s:%d" % (m["ipv4"], EC.vault_etcd_client_port),
            "fleet_etcd_advertise_client_urls":
            "https://%s:%d" % (m["ipv4"], EC.fleet_etcd_client_port),

            # Kubernetes
            "kubernetes_apiserver_insecure_port":
            EC.kubernetes_apiserver_insecure_port,
            "kubernetes_node_ip":
            "%s" % m["ipv4"],
            "kubernetes_node_name":
            "%s" % m["ipv4"] if fqdn == automatic_name else fqdn,
            "kubernetes_service_cluster_ip_range":
            EC.kubernetes_service_cluster_ip_range,

            # Vault are located with the etcd members
            "vault_ip_list":
            ",".join(self.etcd_member_ip_list),
            "vault_port":
            EC.vault_port,
            "kubelet_healthz_port":
            EC.kubelet_healthz_port,
            "etcd_member_kubernetes_control_plane_ip_list":
            ",".join(self.etcd_member_ip_list),
            "etcd_member_kubernetes_control_plane_ip":
            self.etcd_member_ip_list,
            "hyperkube_image_url":
            EC.hyperkube_image_url,
            "cephtools_image_url":
            EC.cephtools_image_url,
            # IPAM
            "cni":
            json.dumps(cni_attr, sort_keys=True),
            "network": {
                "cidrv4": m["cidrv4"],
                "gateway": m["gateway"],
                "ip": m["ipv4"],
                "subnet": cni_attr["subnet"],
                "perennial_host_ip": EC.perennial_local_host_ip,
                "ip_or_fqdn":
                fqdn if EC.sync_replace_ip_by_fqdn else m["ipv4"],
            },
            # host
            "hostname":
            dns_attr["shortname"],
            "dns_attr":
            dns_attr,
            "nameservers":
            " ".join(EC.nameservers),
            "ntp":
            " ".join(EC.ntp),
            "fallbackntp":
            " ".join(EC.fallbackntp),
            "vault_polling_sec":
            EC.vault_polling_sec,
            "lifecycle_update_polling_sec":
            EC.lifecycle_update_polling_sec,
            "disk_profile":
            self.compute_disks_size(m["disks"]),
        }
        selector = {"mac": m["mac"]}
        selector.update(self.get_extra_selectors(self.extra_selector))
        if update_extra_metadata:
            extra_metadata.update(update_extra_metadata)
        gen = generator.Generator(
            api_uri=self.api_uri,
            group_id="%s-%d" % (marker, i),  # one per machine
            profile_id=marker,  # link to ignition
            name=marker,
            ignition_id="%s.yaml" % self.ignition_dict[marker],
            matchbox_path=self.matchbox_path,
            selector=selector,
            extra_metadata=extra_metadata,
        )
        gen.dumps()
    def test_03(self):
        nb_node = 3
        marker = "euid-%s-%s" % (TestKVMDiscoveryClient.__name__.lower(),
                                 self.test_03.__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:
            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=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)
                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)

            # Checks
            self.assertEqual(len(interfaces), 3)

            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.assertEqual(1,
                             len(set([k["chassis_name"] for k in interfaces])))

            self.write_ending(marker)
        finally:
            if os.getenv("TEST"):
                self.iteractive_usage()
            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)