Exemplo n.º 1
0
  def test_update_metadata_contains_correct_nodes(self, m_NutanixRestApiClient):
    m_prism_client = mock.MagicMock(spec=NutanixRestApiClient)
    m_NutanixRestApiClient.from_proto.return_value = m_prism_client

    def fake_clusters_get(**kwargs):
      cluster_data = {"clusterUuid": "fake-cluster-id"}
      if kwargs.get("cluster_id"):
        return cluster_data
      else:
        return {"entities": [cluster_data]}

    m_prism_client.clusters_get.side_effect = fake_clusters_get

    cluster = AcropolisCluster(self.cluster_metadata)
    with mock.patch.object(cluster, "identifier_to_node_uuid") as m_itnu:
      m_itnu.side_effect = ["this", "that", "the other", "and the last one"]
      self.assertEqual(4, len(cluster.nodes()))
Exemplo n.º 2
0
  def test_nodes_if_cluster_contains_fewer_nodes(self, m_NutanixRestApiClient):
    m_prism_client = mock.MagicMock(spec=NutanixRestApiClient)
    m_NutanixRestApiClient.from_proto.return_value = m_prism_client

    def fake_clusters_get(**kwargs):
      cluster_data = {"clusterUuid": "fake-cluster-id"}
      if kwargs.get("cluster_id"):
        return cluster_data
      else:
        return {"entities": [cluster_data]}

    m_prism_client.clusters_get.side_effect = fake_clusters_get
    m_prism_client.hosts_get.return_value = {
      "entities": [
        {
          "clusterUuid": "fake-cluster-id",
          "uuid": "fake_node_uuid_0"
        },
        {
          "clusterUuid": "fake-cluster-id",
          "uuid": "fake_node_uuid_1"
        },
        {
          "clusterUuid": "fake-cluster-id",
          "uuid": "fake_node_uuid_2"
        },
        {
          "clusterUuid": "fake-cluster-id",
          "uuid": "fake_node_uuid_3"
        },
      ]
    }

    del self.cluster_metadata.cluster_nodes[-1]  # Remove the last item.
    cluster = AcropolisCluster(self.cluster_metadata)
    with mock.patch.object(cluster, "identifier_to_node_uuid") as m_itnu:
      m_itnu.side_effect = ["fake_node_uuid_0",
                            "fake_node_uuid_1",
                            "fake_node_uuid_2",
                            "fake_node_uuid_3"]
      self.assertEqual(3, len(cluster.nodes()))
Exemplo n.º 3
0
  def test_nodes(self):
    cluster_nodes = self.cluster_metadata.cluster_nodes
    del cluster_nodes[:]
    for index in range(1, 5):
      node = cluster_nodes.add()
      node.id = "aaaaaaaa-aaaa-aaaa-0001-00000000000%d" % index
      oob_info = node.node_out_of_band_management_info
      oob_info.interface_type = oob_info.kIpmi

    cluster = AcropolisCluster(self.cluster_metadata)
    hosts_get_data = {
      "metadata": {},
      "entities": [
        {
          "serviceVMId": "aaaaaaaa-aaaa-aaaa-0000-000000000001",
          "uuid": "aaaaaaaa-aaaa-aaaa-0001-000000000001",
          "name": "RTP-Test-14-1",
          "serviceVMExternalIP": "10.60.4.71",
          "hypervisorAddress": "10.60.5.71",
          "controllerVmBackplaneIp": "10.60.4.71",
          "managementServerName": "10.60.5.71",
          "ipmiAddress": "10.60.2.71",
          "hypervisorState": "kAcropolisNormal",
          "state": "NORMAL",
          "clusterUuid": "aaaaaaaa-aaaa-aaaa-0002-000000000000",
          "stats": {},
          "usageStats": {},
        },
        {
          "serviceVMId": "aaaaaaaa-aaaa-aaaa-0000-000000000002",
          "uuid": "aaaaaaaa-aaaa-aaaa-0001-000000000002",
          "name": "RTP-Test-14-2",
          "serviceVMExternalIP": "10.60.4.72",
          "hypervisorAddress": "10.60.5.72",
          "controllerVmBackplaneIp": "10.60.4.72",
          "managementServerName": "10.60.5.72",
          "ipmiAddress": "10.60.2.72",
          "hypervisorState": "kAcropolisNormal",
          "state": "NORMAL",
          "clusterUuid": "aaaaaaaa-aaaa-aaaa-0002-000000000000",
          "stats": {},
          "usageStats": {},
        },
        {
          "serviceVMId": "aaaaaaaa-aaaa-aaaa-0000-000000000003",
          "uuid": "aaaaaaaa-aaaa-aaaa-0001-000000000003",
          "name": "RTP-Test-14-3",
          "serviceVMExternalIP": "10.60.4.73",
          "hypervisorAddress": "10.60.5.73",
          "controllerVmBackplaneIp": "10.60.4.73",
          "managementServerName": "10.60.5.73",
          "ipmiAddress": "10.60.2.73",
          "hypervisorState": "kAcropolisNormal",
          "state": "NORMAL",
          "clusterUuid": "aaaaaaaa-aaaa-aaaa-0002-000000000000",
          "stats": {},
          "usageStats": {},
        },
        {
          "serviceVMId": "aaaaaaaa-aaaa-aaaa-0000-000000000004",
          "uuid": "aaaaaaaa-aaaa-aaaa-0001-000000000004",
          "name": "RTP-Test-14-4",
          "serviceVMExternalIP": "10.60.4.74",
          "hypervisorAddress": "10.60.5.74",
          "controllerVmBackplaneIp": "10.60.4.74",
          "managementServerName": "10.60.5.74",
          "ipmiAddress": "10.60.2.74",
          "hypervisorState": "kAcropolisNormal",
          "state": "NORMAL",
          "clusterUuid": "aaaaaaaa-aaaa-aaaa-0002-000000000000",
          "stats": {},
          "usageStats": {},
        },
      ]
    }

    def fake_hosts_get_by_id(host_id, *args, **kwargs):
      for host in hosts_get_data["entities"]:
        if host["uuid"] == host_id:
          return host
      raise RuntimeError("Host '%s' not found" % host_id)

    with mock.patch("curie.nutanix_rest_api_client.requests.Session.get") as m_get, \
         mock.patch("curie.nutanix_rest_api_client.NutanixRestApiClient.hosts_get_by_id", wraps=fake_hosts_get_by_id) as m_hosts_get_by_id:
      m_response = mock.Mock()
      m_response.status_code = 200
      m_response.content = json.dumps(hosts_get_data)
      m_response.json.return_value = hosts_get_data
      m_get.return_value = m_response

      nodes = cluster.nodes()

      for index, (node, entity) in enumerate(zip(nodes, hosts_get_data["entities"])):
        self.assertIsInstance(node, AcropolisNode)
        self.assertEqual(index, node.node_index())
        self.assertEqual(entity["uuid"], node.node_id())
        self.assertEqual(entity["hypervisorAddress"], node.node_ip())