Esempio n. 1
0
 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()
Esempio n. 2
0
 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)
Esempio n. 3
0
 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'],
                      [])
Esempio n. 4
0
 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()
Esempio n. 5
0
 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
Esempio n. 6
0
 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)