def test_add_cluster_clusterchanged(self): self.vc_driver.state = driver.State.IDLE cluster_mor = resource_util.get_cluster_mor_by_path(self.session, "ClusterComputeResource") old_clu_id = cluster_mor.value object.__setattr__(cluster_mor, "value", "new_value") with contextlib.nested( mock.patch.object(resource_util, "get_cluster_mor_by_path", return_value=cluster_mor), mock.patch.object(self.vc_driver, "_unregister_cluster_for_updates", return_value=None), ): self.assertEqual(cache.VCCache.get_switch_for_cluster_path("ClusterComputeResource"), "test_dvs") self.assertIn(old_clu_id, cache.VCCache.clusters_id_to_path) self.vc_driver.add_cluster("ClusterComputeResource", "new_dvs") self.assertNotIn(old_clu_id, cache.VCCache.clusters_id_to_path) self.assertIn("new_value", cache.VCCache.clusters_id_to_path) self.assertEqual(cache.VCCache.get_switch_for_cluster_path("ClusterComputeResource"), "new_dvs") self.assertEqual(self.vc_driver.state, driver.State.READY)
def validate_cluster_switch_mapping(self, cluster_path, switch): """ Validate the cluster_switch_mapping """ if not cluster_path or not switch: return False, None cluster_mor = resource_util.get_cluster_mor_by_path(self.session, cluster_path) if not cluster_mor: LOG.error(_("Invalid cluster %s "), cluster_path) return False, None else: if not self.is_valid_switch(cluster_mor, switch): LOG.error(_("Invalid Switch %(switch)s for cluster %(path)s"), {'switch': switch, 'path': cluster_path}) return False, None else: LOG.info(_("Cluster %(path)s and switch %(sw)s are validated"), {'path': cluster_path, 'sw': switch}) return True, cluster_mor