def setUp(self):
     super().setUp()
     host_wrapper = HostWrapper()
     host_wrapper.account = ACCOUNT
     host_wrapper.display_name = "host1"  # Same as self.added_hosts[0]
     host_wrapper.insights_id = generate_uuid()
     host_wrapper.stale_timestamp = now().isoformat()
     host_wrapper.reporter = "test"
     response_data = self.post(HOST_URL, [host_wrapper.data()], 207)
     self.added_hosts.append(HostWrapper(response_data["data"][0]["host"]))
 def setUp(self):
     super().setUp()
     # add a host with no insights id
     host_wrapper = HostWrapper()
     host_wrapper.account = ACCOUNT
     host_wrapper.id = generate_uuid()
     host_wrapper.satellite_id = generate_uuid()
     host_wrapper.stale_timestamp = now().isoformat()
     host_wrapper.reporter = "test"
     self.post(HOST_URL, [host_wrapper.data()], 207)
Exemple #3
0
    def create_hosts(self):
        hosts_to_create = [
            (
                "host1",
                generate_uuid(),
                "host1.domain.test",
                [
                    {
                        "namespace": "NS1",
                        "key": "key1",
                        "value": "val1"
                    },
                    {
                        "namespace": "NS1",
                        "key": "key2",
                        "value": "val1"
                    },
                    {
                        "namespace": "SPECIAL",
                        "key": "tag",
                        "value": "ToFind"
                    },
                    {
                        "namespace": "no",
                        "key": "key",
                        "value": None
                    },
                ],
            ),
            (
                "host2",
                generate_uuid(),
                "host1.domain.test",
                [
                    {
                        "namespace": "NS1",
                        "key": "key1",
                        "value": "val1"
                    },
                    {
                        "namespace": "NS2",
                        "key": "key2",
                        "value": "val2"
                    },
                    {
                        "namespace": "NS3",
                        "key": "key3",
                        "value": "val3"
                    },
                ],
            ),  # the same fqdn is intentional
            (
                "host3",
                generate_uuid(),
                "host2.domain.test",
                [
                    {
                        "namespace": "NS2",
                        "key": "key2",
                        "value": "val2"
                    },
                    {
                        "namespace": "NS3",
                        "key": "key3",
                        "value": "val3"
                    },
                    {
                        "namespace": "NS1",
                        "key": "key3",
                        "value": "val3"
                    },
                    {
                        "namespace": None,
                        "key": "key4",
                        "value": "val4"
                    },
                    {
                        "namespace": None,
                        "key": "key5",
                        "value": None
                    },
                ],
            ),
        ]

        if hasattr(self, "hosts_to_create"):
            self.hosts_to_create = hosts_to_create + self.hosts_to_create
        else:
            self.hosts_to_create = hosts_to_create

        host_list = []

        mock_event_producer = MockEventProducer()

        for host in self.hosts_to_create:
            host_wrapper = HostWrapper()
            host_wrapper.account = ACCOUNT
            host_wrapper.display_name = host[0]
            host_wrapper.insights_id = generate_uuid()
            host_wrapper.rhel_machine_id = generate_uuid()
            host_wrapper.subscription_manager_id = generate_uuid()
            host_wrapper.satellite_id = generate_uuid()
            host_wrapper.bios_uuid = generate_uuid()
            host_wrapper.ip_addresses = ["10.0.0.2"]
            host_wrapper.fqdn = host[2]
            host_wrapper.mac_addresses = ["aa:bb:cc:dd:ee:ff"]
            host_wrapper.external_id = generate_uuid()
            host_wrapper.facts = [{
                "namespace": "ns1",
                "facts": {
                    "key1": "value1"
                }
            }]
            host_wrapper.tags = host[3]
            host_wrapper.stale_timestamp = now().isoformat()
            host_wrapper.reporter = "test"
            message = {"operation": "add_host", "data": host_wrapper.data()}

            with self.app.app_context():
                handle_message(json.dumps(message), mock_event_producer)

            response_data = json.loads(mock_event_producer.event)

            # add facts object since it's not returned by message
            host_data = {
                **response_data["host"], "facts": message["data"]["facts"]
            }
            host_list.append(HostWrapper(host_data))

        return host_list