Example #1
0
  def test_update_metadata_if_cluster_contains_extra_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"
        },
      ]
    }

    extra_node = self.cluster_metadata.cluster_nodes.add()
    extra_node.id = "fake_node_extra"

    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",
                            CurieException(CurieError.kInvalidParameter,
                                           "Unable to locate host.")]
      with self.assertRaises(CurieTestException) as ar:
        cluster.update_metadata(False)

    self.assertIn(
      "Cause: Node with ID 'fake_node_extra' is in the Curie cluster "
      "metadata, but not found in the AHV cluster.\n"
      "\n"
      "Impact: The cluster configuration is invalid.\n"
      "\n"
      "Corrective Action: Please check that all of the nodes in the Curie "
      "cluster metadata are part of the AHV cluster. For example, if the "
      "cluster configuration has four nodes, please check that all four nodes "
      "are present in the AHV cluster.\n"
      "\n"
      "Traceback (most recent call last):", str(ar.exception))
Example #2
0
  def test_update_metadata(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"
        },
      ]
    }

    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",
                            CurieException(CurieError.kInvalidParameter,
                                           "Unable to locate host.")]
      cluster.update_metadata(False)

    for index, node_metadata in enumerate(cluster.metadata().cluster_nodes):
      self.assertEqual("fake_node_uuid_%d" % index, node_metadata.id)
Example #3
0
  def test_update_metadata_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",
                            CurieException(CurieError.kInvalidParameter,
                                           "Unable to locate host.")]
      cluster.update_metadata(False)
Example #4
0
  def test_update_metadata_version(self, m_NutanixRestApiClient):
    m_prism_client = mock.MagicMock(spec=NutanixRestApiClient)
    m_NutanixRestApiClient.from_proto.return_value = m_prism_client

    m_prism_client.hosts_get.return_value = {
      "entities": [
        {
          "clusterUuid": "fake-cluster-id",
          "uuid": "fake_node_uuid_0",
          "hypervisorAddress": "1.1.1.0",
          "serviceVMExternalIP": "2.2.2.0",
          "name": "MockEntity",
          "numCpuSockets": 2,
          "numCpuCores": 32,
          "numCpuThreads": 64,
          "cpuFrequencyInHz": int(3e9),
          "memoryCapacityInBytes": int(32e9),
        },
        {
          "clusterUuid": "fake-cluster-id",
          "uuid": "fake_node_uuid_1",
          "hypervisorAddress": "1.1.1.1",
          "serviceVMExternalIP": "2.2.2.1",
          "name": "MockEntity",
          "numCpuSockets": 2,
          "numCpuCores": 32,
          "numCpuThreads": 64,
          "cpuFrequencyInHz": int(3e9),
          "memoryCapacityInBytes": int(32e9),
        },
        {
          "clusterUuid": "fake-cluster-id",
          "uuid": "fake_node_uuid_2",
          "hypervisorAddress": "1.1.1.2",
          "serviceVMExternalIP": "2.2.2.2",
          "name": "MockEntity",
          "numCpuSockets": 2,
          "numCpuCores": 32,
          "numCpuThreads": 64,
          "cpuFrequencyInHz": int(3e9),
          "memoryCapacityInBytes": int(32e9),
        },
        {
          "clusterUuid": "fake-cluster-id",
          "uuid": "fake_node_uuid_3",
          "hypervisorAddress": "1.1.1.3",
          "serviceVMExternalIP": "2.2.2.3",
          "name": "MockEntity",
          "numCpuSockets": 2,
          "numCpuCores": 32,
          "numCpuThreads": 64,
          "cpuFrequencyInHz": int(3e9),
          "memoryCapacityInBytes": int(32e9),
        },
      ]
    }
    nm = NutanixMetadata()
    nm.version = "el6-release-euphrates-5.0.2-stable-9d20638eb2ba1d3f84f213d5976fbcd412630c6d"
    m_prism_client.get_nutanix_metadata.return_value = nm

    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 = ["fake_node_uuid_0",
                            "fake_node_uuid_1",
                            "fake_node_uuid_2",
                            "fake_node_uuid_3",
                            CurieException(CurieError.kInvalidParameter,
                                           "Unable to locate host.")]
      cluster.update_metadata(include_reporting_fields=True)
    self.assertEquals(
      nm.version,
      cluster._metadata.cluster_software_info.nutanix_info.version)