Ejemplo n.º 1
0
    def test_terraform_call_fails(self, mock_check_call):
        """
        Testing validate_terraform fails when terraform call fails
        """
        mock_check_call.side_effect = subprocess.CalledProcessError(1, None)
        mock_check_call.return_value = "Terraform v0.6.16"
        config = {
            "terraform": "./terraform",
            "terraform_version_check": "Terraform v0.9.11",
            "production": False,
        }
        with LogCapture(level=logging.CRITICAL) as crit:
            with self.assertRaises(AssertionError):
                bootstrap.validate_terraform(self.directory, config)
            crit_logs = set(crit.actual())

            message_1 = (
                "[critical ] See documentation for installing terraform: "
                "http://bit.ly/2ufjQ0R [dsi.bootstrap] ")
            message_2 = "[critical ] Call to terraform failed.      [dsi.bootstrap] "
            crit_expected = {
                ("dsi.bootstrap", "CRITICAL", message_1),
                ("dsi.bootstrap", "CRITICAL", message_2),
            }
            self.assertTrue(crit_expected.issubset(crit_logs))
Ejemplo n.º 2
0
 def test_terraform_not_found(self, mock_check_output):
     """
     Testing validate_terraform fails when terraform is not found
     """
     mock_check_output.side_effect = subprocess.CalledProcessError(
         127, None)
     mock_check_output.return_value = "Terraform v0.6.16"
     config = copy.copy(self.TERRAFORM_CONFIG)
     with LogCapture(level=logging.CRITICAL) as crit:
         with self.assertRaises(AssertionError):
             bootstrap.validate_terraform(self.directory, config)
         crit_logs = set(crit.actual())
         crit_expected = {
             (
                 "dsi.bootstrap",
                 "CRITICAL",
                 "[critical ] See documentation for installing terraform: http://bit.ly/2ufjQ0R [dsi.bootstrap] ",
             ),
             (
                 "dsi.bootstrap",
                 "CRITICAL",
                 "[critical ] No terraform binary file found. [dsi.bootstrap] ",
             ),
         }
         self.assertTrue(crit_expected.issubset(crit_logs))
Ejemplo n.º 3
0
    def test_terraform_wrong_version(self, mock_check_output):
        """
        Testing validate_terraform fails on incorrect version
        """
        # pylint: disable=line-too-long
        mock_check_output.return_value = "Terraform v0.6.16"
        config = {
            "terraform": "./terraform",
            "terraform_version_check": "Terraform v0.9.11",
            "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",
            "production": False,
        }
        with LogCapture(level=logging.CRITICAL) as crit:
            with self.assertRaises(AssertionError):
                bootstrap.validate_terraform(self.directory, config)
            actual = crit.actual()
            expected = (
                "dsi.bootstrap",
                "CRITICAL",
                "[critical ] No Terraform download url found for your operating system. Automatic terraform download is not supported.",
            )
            # pylint: disable=import-outside-toplevel
            import pprint

            pprint.pprint(actual)
            self.assertEqual(expected[0], crit.records[0].name)
            self.assertEqual(expected[1], crit.records[0].levelname)
            self.assertTrue(crit.records[0].getMessage().startswith(
                expected[2]))
Ejemplo n.º 4
0
 def test_terraform_valid(self, mock_check_output):
     """
     Testing validate_terraform with valid inputs
     """
     mock_check_output.return_value = "Terraform v0.9.11"
     config = copy.copy(self.TERRAFORM_CONFIG)
     bootstrap.validate_terraform(self.directory, config)
     self.assertEqual(config, config)