Exemplo n.º 1
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)
Exemplo n.º 2
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",
                         "[error    ] Clusters already exist in mongodb_setup.out.atlas.clusters. [common.atlas_setup] ",
                     ),
                     (
                         "common.atlas_setup",
                         "ERROR",
                         "[error    ] Please shutdown existing clusters first with infrastructure_teardown.py. [common.atlas_setup] ",
                     ),
                 )
Exemplo n.º 3
0
 def causes_exception(self, subdict):
     """
     Helper method - assert we get an exception when `subdict` is inserted into an out config
     """
     with in_dir(FIXTURE_FILES.fixture_file_path("nested-config")):
         conf = load_config_dict("mongodb_setup")
         with self.assertRaises(config.InvalidConfigurationException):
             conf["mongodb_setup"]["out"] = {"okay": [subdict]}
Exemplo n.º 4
0
 def test_find_nested_config_dicts(self):
     """
     We check for duplicate ids in lists of lists correctly.
     """
     with in_dir(FIXTURE_FILES.fixture_file_path("invalid-ids-in-lists")):
         with self.assertRaises(config.InvalidConfigurationException):
             conf = ConfigDict("mongodb_setup")
             conf.load()
Exemplo n.º 5
0
 def test_variable_reference_contains_invalid_id(self):
     """
     Variable references cannot evaluate to blocks containing duplicate ids.
     """
     with in_dir(FIXTURE_FILES.fixture_file_path("nested-invalid-ids")):
         with self.assertRaises(config.InvalidConfigurationException):
             conf = ConfigDict("mongodb_setup")
             conf.load()
Exemplo n.º 6
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()
Exemplo n.º 7
0
 def test_set_invalid_key(self):
     """can't use conf[key] = X with key invalid"""
     with in_dir(FIXTURE_FILES.fixture_file_path("nested-config")):
         conf = load_config_dict("mongodb_setup")
         self.assertEqual(
             conf["mongodb_setup"]["this"]["is"]["quite"]["deeply"]
             ["nested"], "okay")
         conf["mongodb_setup"]["out"] = {}
         conf["mongodb_setup"]["out"]["safe-key"] = "💃"
         self.assertEqual(conf["mongodb_setup"]["out"]["safe-key"], "💃")
Exemplo n.º 8
0
 def causes_id_exception(self, subdict):
     """
     Helper method - assert we get an exception when subdict is inserted into a config.
     Note: These tests explicitly test `validate_id` when called from `_yaml_load` (as opposed to
     when it's called from `assert_valid_ids`).
     """
     with in_dir(FIXTURE_FILES.fixture_file_path("invalid-ids")):
         conf = load_config_dict("mongodb_setup")
         with self.assertRaises(config.InvalidConfigurationException):
             conf["mongodb_setup"]["test"] = {"okay": [subdict]}
Exemplo n.º 9
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)
Exemplo n.º 10
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"],
                      [])
Exemplo n.º 11
0
 def test_assigns_invalid_nested_dict_multiple_errors(self):
     """assign invalid key from a nested dict with multiple errors"""
     with in_dir(FIXTURE_FILES.fixture_file_path("nested-config")):
         conf = load_config_dict("mongodb_setup")
         with self.assertRaises(
                 config.InvalidConfigurationException) as context:
             conf["mongodb_setup"]["out"] = {
                 "okay": [{
                     "okay":
                     "this is fine",
                     "not okay":
                     "you're killing me, bro!",
                     "seriously, just stop now":
                     "but all the cool kids are doing it",
                 }]
             }
         # we're non-normative on what the actual message is, but we
         # do care that all the errored keys are there
         self.assertRegex(str(context.exception), r"not okay")
         self.assertRegex(str(context.exception), r"seriously")
Exemplo n.º 12
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()
Exemplo n.º 13
0
 def test_load_yaml_invalid_keys(self):
     """can't even get bad keys from yaml"""
     with in_dir(FIXTURE_FILES.fixture_file_path("invalid-config")):
         with self.assertRaises(config.InvalidConfigurationException):
             ConfigDict("mongodb_setup").load()