def testGetMasterIpAddress(self): cluster_info = datastore.ClusterInfo() cluster_info.put() instance_info = datastore.InstanceInfo(parent=cluster_info.key, external_ip='1.2.3.4') instance_info.put() cluster_info.master = instance_info.key cluster_info.put() self.assertEqual('1.2.3.4', cluster_info.GetMasterIpAddress())
def testStatusChange(self): cluster_info = datastore.ClusterInfo() cluster_info.put() cluster_info.SetStatus(datastore.ClusterStatus.READY) self.assertEqual(datastore.ClusterStatus.READY, cluster_info.status) all_clusters = datastore.ClusterInfo.query().fetch() self.assertEqual(1, len(all_clusters)) cluster_info = all_clusters[0] self.assertEqual(datastore.ClusterStatus.READY, cluster_info.status)
def testCascadeDelete(self): cluster_info = datastore.ClusterInfo() cluster_info.put() instance_info = datastore.InstanceInfo(parent=cluster_info.key) instance_info.put() all_instances = datastore.InstanceInfo.query().fetch() self.assertEqual(1, len(all_instances)) cluster_info.key.delete() all_instances = datastore.InstanceInfo.query().fetch() self.assertEqual(0, len(all_instances))
def testTeardownCluster(self): """Unit test of TeardownCluster().""" parent_mock = self._SetUpMocksForClusterStart() # Create a sequence of return values for mock method calls. # The dummy list with two values: the first value is a list of resources and # the second value is an empty list, which indicates that the list of # resources have been deleted in this unit test. dummy_list = [[{ 'name': 'fugafuga' }, { 'name': 'hogehoge' }, { 'name': 'piyopiyo' }], []] parent_mock.ListInstances.side_effect = dummy_list parent_mock.GetInstance.return_value = None parent_mock.ListDisks.side_effect = dummy_list parent_mock.GetDisk.return_value = None cluster_info = datastore.ClusterInfo(prefix='managed', project='project-hoge', zone='zone-fuga') cluster_info.put() hadoop_cluster.HadoopCluster( 'DUMMY HTTP', cluster_id=cluster_info.key.id()).TeardownCluster() parent_mock.GceApi.assert_called_once_with( 'project-hoge', 'zone-fuga', authorized_http='DUMMY HTTP') parent_mock.ListInstances.assert_called_with( 'name eq "managed-hadoop-master|^managed-hadoop-worker-\\d+$"') # Make sure DeleteInstance() is called for each instance. self.assertEqual([ mock.call('fugafuga'), mock.call('hogehoge'), mock.call('piyopiyo') ], parent_mock.DeleteInstance.call_args_list) parent_mock.ListDisks.assert_called_with( 'name eq "managed-hadoop-master|^managed-hadoop-worker-\\d+$"') # Make sure DeleteDisk() is called for each disk. self.assertEqual([ mock.call('fugafuga'), mock.call('hogehoge'), mock.call('piyopiyo') ], parent_mock.DeleteDisk.call_args_list)
def testTeardownCluster_NoInstance(self): """Unit test of TeardownCluster() with no instance returned by list.""" parent_mock = self._SetUpMocksForClusterStart() # ListInstances() returns empty list. parent_mock.ListInstances.return_value = [] parent_mock.GetInstance.return_value = None cluster_info = datastore.ClusterInfo(prefix='managed', project='project-hoge', zone='zone-fuga') cluster_info.put() hadoop_cluster.HadoopCluster( 'DUMMY HTTP', cluster_id=cluster_info.key.id()).TeardownCluster() parent_mock.GceApi.assert_called_once_with( 'project-hoge', 'zone-fuga', authorized_http='DUMMY HTTP') parent_mock.ListInstances.assert_called_with( 'name eq "managed-hadoop-master|^managed-hadoop-worker-\\d+$"') # Make sure DeleteInstance() is not called. self.assertFalse(parent_mock.DeleteInstance.called)