def test_build_hosts_file(self): expected = [ '10.2.1.1\tmd md0 mongod0 mongod0.dsitest.dev', '10.2.1.2\tmd1 mongod1 mongod1.dsitest.dev', '10.2.1.3\tmd2 mongod2 mongod2.dsitest.dev', '10.2.1.4\tmd3 mongod3 mongod3.dsitest.dev', '10.2.1.5\tmd4 mongod4 mongod4.dsitest.dev', '10.2.1.6\tmd5 mongod5 mongod5.dsitest.dev', '10.2.1.7\tmd6 mongod6 mongod6.dsitest.dev', '10.2.1.8\tmd7 mongod7 mongod7.dsitest.dev', '10.2.1.9\tmd8 mongod8 mongod8.dsitest.dev', '10.2.1.100\tms ms0 mongos0 mongos0.dsitest.dev', '10.2.1.101\tms1 mongos1 mongos1.dsitest.dev', '10.2.1.102\tms2 mongos2 mongos2.dsitest.dev', '10.2.1.51\tcs cs0 configsvr0 configsvr0.dsitest.dev', '10.2.1.52\tcs1 configsvr1 configsvr1.dsitest.dev', '10.2.1.53\tcs2 configsvr2 configsvr2.dsitest.dev', '10.2.1.10\twc wc0 workload_client0 workload_client0.dsitest.dev' ] config_files = os.path.dirname(os.path.abspath(__file__)) + '/../../docs/config-specs/' with test_config.in_dir(config_files): real_config_dict = ConfigDict('infrastructure_provisioning') real_config_dict.load() real_config_dict.save = MagicMock(name='save') provisioner = ip.Provisioner(real_config_dict, provisioning_file=self.provision_log_path) hosts_contents = provisioner._build_hosts_file() self.assertEqual(expected, hosts_contents)
def test_start_custom_build(self, mock_create_custom_build): expected_url = 'https://cloud.mongodb.com/api/private/MOCK/URL/nds/groups/test_group_id/clusters' with in_dir( FIXTURE_FILES.fixture_file_path('atlas-config-custom-build')): self.config = load_config_dict('mongodb_setup') self._test_start(expected_url) mock_create_custom_build.assert_called()
def test_unique_name(self): atlas_cluster = { 'clusterType': 'REPLSET', 'providerSettings': { 'instanceSizeName': 'M99' } } with in_dir(FIXTURE_FILES.fixture_file_path('atlas-config')): config = load_config_dict('mongodb_setup') atlas = atlas_setup.AtlasSetup(config) name = atlas._generate_unique_name(atlas_cluster) # Generated name looks like: dsi-M99-abcdefg # (The last part is random, but fixed length.) self.assertRegex(name, 'dsi-M99-') self.assertEqual(len(name), 15)
def test_setup_hostnames(self, mock_exec_command, mock_create_file, mock_ssh): _ = mock_ssh config_files = os.path.dirname(os.path.abspath(__file__)) + '/../../docs/config-specs/' with test_config.in_dir(config_files): real_config_dict = ConfigDict('infrastructure_provisioning') real_config_dict.load() real_config_dict.save = MagicMock(name='save') provisioner = ip.Provisioner(real_config_dict, provisioning_file=self.provision_log_path) provisioner.setup_hostnames() out = provisioner.config['infrastructure_provisioning']['out'] self.assertEqual(out['mongod'][0]['private_hostname'], 'mongod0.dsitest.dev') self.assertEqual(out['configsvr'][2]['private_hostname'], 'configsvr2.dsitest.dev') self.assertEqual(mock_create_file.call_count, 16) self.assertEqual(mock_exec_command.call_count, 16)
def test_destroy(self, mock_delete, mock_generate, mock_get_one_cluster): with in_dir(FIXTURE_FILES.fixture_file_path('atlas-config')): config = load_config_dict('mongodb_setup') # Inject a fake cluster into mongodb_setup.out config['mongodb_setup']['out'] = {} config['mongodb_setup']['out']['atlas'] = {} config['mongodb_setup']['out']['atlas']['clusters'] = [{ 'name': 'some_other_unique_name', 'stateName': 'IDLE' }] atlas = atlas_setup.AtlasSetup(config) atlas.destroy() mock_delete.assert_called_with( 'https://cloud-dev.mongodb.com/api/atlas/v1.0/MOCK/URL/groups/test_group_id/clusters/some_other_unique_name', auth=ANY) self.assertEqual(config['mongodb_setup']['out']['atlas']['clusters'], [])
def test_log_collection(self, mock_create, mock_get, mock_download, mock_sleep): mock_create.return_value = '12345abcdef' mock_get.side_effect = [{'status': 'FOO'}, {'status': 'SUCCESS'}] with in_dir(FIXTURE_FILES.fixture_file_path('atlas-config')): config = load_config_dict('mongodb_setup') # Inject a fake cluster into mongodb_setup.out config['mongodb_setup']['out'] = {} config['mongodb_setup']['out']['atlas'] = {} config['mongodb_setup']['out']['atlas']['clusters'] = [{ 'name': 'mock_cluster_name', 'clusterType': 'REPLSET', 'stateName': 'IDLE' }] atlas = atlas_setup.AtlasSetup(config) atlas.download_logs('post_task') mock_download.assert_called_with( '12345abcdef', 'reports/post_task/mock_cluster_name.tgz') mock_sleep.assert_called()
def test_start_when_cluster_exists(self): with in_dir(FIXTURE_FILES.fixture_file_path('atlas-config')): config = load_config_dict('mongodb_setup') # Inject a fake cluster into mongodb_setup.out config['mongodb_setup']['out'] = {} config['mongodb_setup']['out']['atlas'] = {} config['mongodb_setup']['out']['atlas']['clusters'] = [{ 'name': 'some_other_unique_name', 'stateName': 'IDLE' }] atlas = atlas_setup.AtlasSetup(config) with self.assertRaises(RuntimeError): with LogCapture(level=logging.ERROR) as log_error: self.assertFalse(atlas.start()) log_error.check( ('common.atlas_setup', 'ERROR', u'[error ] Clusters already exist in mongodb_setup.out.atlas.clusters. [common.atlas_setup] '), ('common.atlas_setup', 'ERROR', u'[error ] Please shutdown existing clusters first with infrastructure_teardown.py. [common.atlas_setup] ' )) #yapf: disable
def test_start(self): expected_url = 'https://cloud-dev.mongodb.com/api/atlas/v1.0/MOCK/URL/groups/test_group_id/clusters' with in_dir(FIXTURE_FILES.fixture_file_path('atlas-config')): self.config = load_config_dict('mongodb_setup') self._test_start(expected_url)