def test_load_bootstrap_different_filename(self): """ Testing that load_bootstrap works with alternate file names """ bootstrap_path = os.path.join(whereami.dsi_repo_path("dsi", "tests"), "bootstrap2.yml") directory = os.path.join(whereami.dsi_repo_path("dsi", "tests"), "testdir/") config = {"bootstrap_file": bootstrap_path, "production": False} with open(bootstrap_path, "w") as bootstrap_file: bootstrap_file.write("owner: test_owner") bootstrap.load_bootstrap(config, directory) self.assertEqual(config["owner"], "test_owner")
def test_load_bootstrap_local_file_makedir(self): """ Testing that load_bootstrap makes nonexistent directory and copies into it """ bootstrap_path = os.path.join( os.path.dirname(whereami.dsi_repo_path("dsi", "tests")), "bootstrap.yml") directory = os.path.join(whereami.dsi_repo_path("dsi", "tests"), "testdir/") config = {"bootstrap_file": bootstrap_path, "production": False} with open(bootstrap_path, "w", encoding="utf-8") as bootstrap_file: bootstrap_file.write("owner: test_owner") bootstrap.load_bootstrap(config, directory) self.assertEqual(config["owner"], "test_owner")
def test_load_bootstrap_copy_file_to_local(self): """ Testing that load_bootstrap copies specified file in 'testdir' to local directory """ bootstrap_path = os.path.join(whereami.dsi_repo_path("dsi", "tests"), "bootstrap.yml") bootstrap_directory = os.path.join( whereami.dsi_repo_path("dsi", "tests"), "testdir/") os.mkdir(bootstrap_directory) config = {"bootstrap_file": bootstrap_path, "production": False} with open(bootstrap_path, "w") as bootstrap_file: bootstrap_file.write("owner: test_owner") bootstrap.load_bootstrap(config, whereami.dsi_repo_path("dsi", "tests")) # confirms that load_bootstrap copies file into working directory correctly self.assertEqual(config["owner"], "test_owner")
def test_load_bootstrap_no_file(self): """ Testing that load_bootstrap fails when file doesn't exist """ config = { "bootstrap_file": "./notarealpath/bootstrap.yml", "production": False } directory = os.getcwd() with LogCapture(level=logging.CRITICAL) as crit: with self.assertRaises(AssertionError): bootstrap.load_bootstrap(config, directory) crit.check(( "dsi.bootstrap", "CRITICAL", "[critical ] Location specified for bootstrap.yml is invalid. [dsi.bootstrap] ", ))
def test_load_bootstrap_copy_file_default_to_local(self): """ Testing that load_bootstrap uses local file if --bootstrap-file flag not used """ bootstrap_path = os.path.join(whereami.dsi_repo_path("dsi", "tests"), "bootstrap.yml") bootstrap_directory = os.path.join( whereami.dsi_repo_path("dsi", "tests"), "testdir/") os.mkdir(bootstrap_directory) config = {"production": False} with open(bootstrap_path, "w") as bootstrap_file: bootstrap_file.write("owner: test_owner") current_path = os.getcwd() os.chdir(os.path.join(bootstrap_directory, "..")) bootstrap.load_bootstrap(config, bootstrap_directory) os.chdir(current_path) # confirms that load_bootstrap copies local file into working directory if not specified self.assertEqual(config["owner"], "test_owner")
def test_load_bootstrap_given_file_and_dir(self): """ Testing that load_bootstrap copies file from 'test_old_dir' into 'test_new_dir' without collisions """ bootstrap_path = os.path.join(whereami.dsi_repo_path("dsi", "tests"), "test_old_dir/bootstrap.yml") bootstrap_new_directory = os.path.join( whereami.dsi_repo_path("dsi", "tests"), "test_new_dir/") bootstrap_old_directory = os.path.join( whereami.dsi_repo_path("dsi", "tests"), "test_old_dir/") os.mkdir(bootstrap_new_directory) os.mkdir(bootstrap_old_directory) config = {"bootstrap_file": bootstrap_path, "production": False} with open(bootstrap_path, "w") as bootstrap_file: bootstrap_file.write("platform: test_platform") bootstrap.load_bootstrap(config, bootstrap_new_directory) # confirms that load_bootstrap copies file into working directory correctly self.assertEqual(config["platform"], "test_platform")
def test_load_bootstrap_copy_same_file(self): """ Testing that load_bootstrap copies specified file in 'testdir' to local directory and fails on collision """ bootstrap_path = os.path.join(whereami.dsi_repo_path("dsi", "tests"), "testdir/bootstrap.yml") wrong_bootstrap_path = os.path.join( whereami.dsi_repo_path("dsi", "tests"), "./bootstrap.yml") bootstrap_directory = os.path.join( whereami.dsi_repo_path("dsi", "tests"), "testdir/") os.mkdir(bootstrap_directory) config = {"bootstrap_file": bootstrap_path, "production": False} with open(bootstrap_path, "w") as bootstrap_file: bootstrap_file.write("owner: test_owner") with open(wrong_bootstrap_path, "w") as wrong_bootstrap_file: wrong_bootstrap_file.write("owner: test_owner") with self.assertRaises(AssertionError): bootstrap.load_bootstrap(config, whereami.dsi_repo_path("dsi", "tests"))
def test_load_bootstrap_no_file_specified(self, mock_expansions): """ Testing that load_bootstrap loads defaults into config object without bootstrap.yml """ master_config = { "analysis": "common", "workload_setup": "common", "infrastructure_provisioning": "single", "mongodb_setup": "standalone", "platform": "linux", "production": False, "storageEngine": "wiredTiger", "terraform_linux_download": "https://releases.hashicorp.com/terraform/0.12.16/terraform_0.12.16_linux_amd64.zip", "terraform_mac_download": "https://releases.hashicorp.com/terraform/0.12.16/terraform_0.12.16_darwin_amd64.zip", "terraform_version_check": "Terraform v0.12.16", "test_control": "core", } test_config = {} bootstrap.load_bootstrap(test_config, ".") self.assertEqual(test_config, master_config) mock_expansions.write_if_necessary.assert_has_calls([call(".")])