def test__update_cluster_version_info_vmm(self, m_VmmClient, n_NtnxApiCli): cluster_pb = proto_patch_encryption_support(CurieSettings.Cluster)() mgmt_info = cluster_pb.cluster_management_server_info mgmt_info.vmm_info.SetInParent() software_info = cluster_pb.cluster_software_info software_info.nutanix_info.SetInParent() m_vmm_cli = m_VmmClient.return_value m_vmm_cli.get_nodes.return_value = [{ "ips": ["1.2.3.4"], "fqdn": "node1.somewhere.blah", "name": "node1.somewhere.blah", "id": "157bbf6f-010b-41c6-938b-2a3dc3fae7ca", "bmc_port": "623", "bmc_address": "1.2.3.5", "overall_state": "OK", "state": "Responding", "version": "10.0.14393.351" }, { "ips": ["2.3.4.5"], "fqdn": "node2.somewhere.blah", "name": "node2.somewhere.blah", "id": "4657f9f7-4027-4fc4-bc90-04c16188438d", "bmc_port": "623", "bmc_address": "2.3.4.6", "overall_state": "OK", "state": "Responding", "version": "10.0.14393.351" }, { "ips": ["3.4.5.6"], "fqdn": "node3.somewhere.blah", "name": "node3.somewhere.blah", "id": "a4b928cf-2d16-43a1-9139-f98d4cbd55d6", "bmc_port": "623", "bmc_address": "3.4.5.7", "overall_state": "OK", "state": "Responding", "version": "10.0.14393.351" }] m_vmm_cli.get_vmm_version.return_value = "4.1.0.1" m_ntnx_api = n_NtnxApiCli.return_value cluster_inc_id = 12345 cluster_uuid = str(uuid.uuid4()) cluster_version = "el6-release-euphrates-5.0.2-stable-9d20638eb2ba1d3f84f213d5976fbcd412630c6d" m_ntnx_api.get_nutanix_metadata.return_value = NutanixMetadata( version=cluster_version, cluster_uuid=cluster_uuid, cluster_incarnation_id=cluster_inc_id) DiscoveryUtil.update_cluster_version_info(cluster_pb) self.assertEqual(cluster_pb.cluster_software_info.nutanix_info.version, "5.0.2") self.assertEqual( cluster_pb.cluster_management_server_info.vmm_info.vmm_version, "4.1.0.1") self.assertEqual( cluster_pb.cluster_hypervisor_info.hyperv_info.version, ["10.0.14393.351", "10.0.14393.351", "10.0.14393.351"])
def test_get_pc_uuid_header_master_version(self, get_nutanix_metadata, get_pc_uuid, **kwargs): get_nutanix_metadata.return_value = NutanixMetadata( version=TestPrismAPIVersions.VALID_AOS_MASTER_VERSION) client = NutanixRestApiClient(self.HOSTS[0], "user", "password") header = client._get_pc_uuid_header() self.assertEqual(header, {})
def test_get_pc_uuid_header_over_5_8(self, get_nutanix_metadata, **kwargs): get_nutanix_metadata.return_value = NutanixMetadata( version="el7.3-release-euphrates-5.8-stable-" "4c26d1af153833c54b67536fb0a4044e6e8c1b07") client = NutanixRestApiClient(self.HOSTS[0], "user", "password") header = client._get_pc_uuid_header() self.assertEqual(header, {})
def test_get_pc_uuid_header_under_5_5(self, get_nutanix_metadata, **kwargs): get_nutanix_metadata.return_value = NutanixMetadata( version="el6-release-danube-4.6-stable-" "ee1b1aab1ac3a630694d9fd45ac1c6b91c1d3dd5") client = NutanixRestApiClient(self.HOSTS[0], "user", "password") header = client._get_pc_uuid_header() self.assertEqual(header, {})
def test_get_pc_uuid_header_5_5(self, get_nutanix_metadata, get_pc_uuid, **kwargs): get_nutanix_metadata.return_value = NutanixMetadata( version="el7.3-release-euphrates-5.5.0.5-stable-" "0f7655edaa04231239690f59cfb9fce39377ef89") get_pc_uuid.return_value = "UUID-UUID-UUID-UUID-UUID" client = NutanixRestApiClient(self.HOSTS[0], "user", "password") header = client._get_pc_uuid_header() self.assertEqual(header, {"X-NTNX-PC-UUID": "UUID-UUID-UUID-UUID-UUID"})
def setUp(self): # Patch get_nutanix_metadata to return a version that is compatible with # Genesis RPCs. We don't care about the cluster UUID/incarnation ID. NutanixRestApiClient.get_nutanix_metadata = mock.Mock( return_value=NutanixMetadata( version="el6-release-danube-4.6-stable-" "ee1b1aab1ac3a630694d9fd45ac1c6b91c1d3dd5")) patch_time = mock.patch("curie.nutanix_rest_api_client.time") self.mock_time = patch_time.start() self.addCleanup(patch_time.stop) self.mock_time.sleep.return_value = 0
def test_get_pc_uuid_header_5_5_unsupported_version( self, get_nutanix_metadata, get_pc_uuid, **kwargs): get_nutanix_metadata.return_value = NutanixMetadata( version="el7.3-release-euphrates-5.5-stable-" "cbd9acfdebb3c7fd70ff2b4c4061515daadb50b1") get_pc_uuid.return_value = "UUID-UUID-UUID-UUID-UUID" # Get version client = NutanixRestApiClient(self.HOSTS[0], "user", "password") with self.assertRaises(CurieException) as ar: client._get_pc_uuid_header() self.assertEqual(str(ar.exception), ( "Cluster is running a 5.5 version which is incompatible with X-Ray " "when connected to Prism Central. Please upgrade AOS to 5.5.0.2 or " "newer, or disconnect Prism Central."))
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)