Example #1
0
    def test_config_environment_extraction(self):
        """
        The provider serialization loads keys as needed from the environment.

        Variables from the configuration take precendence over those from
        the environment, when serializing.
        """
        config = {
            "access-key": "secret-12345",
            "secret-key": "secret-abc",
            "authorized-keys": "0123456789abcdef"
        }

        environ = {
            "AWS_SECRET_ACCESS_KEY": "secret-abc",
            "AWS_ACCESS_KEY_ID": "secret-123"
        }

        self.change_environment(**environ)
        provider = MachineProvider(self.env_name, {
            "access-key": "secret-12345",
            "authorized-keys": "0123456789abcdef"
        })
        serialized = provider.get_serialization_data()
        self.assertEqual(config, serialized)
Example #2
0
    def get_provider(self):
        """Return the ec2 machine provider.

        This should only be invoked after mocker is in replay mode so the
        AWS service class will be appropriately replaced by the mock.
        """
        return MachineProvider(self.env_name, self.get_config())
Example #3
0
 def setUp(self):
     super(EC2ProviderFunctionalTest, self).setUp()
     self.username = pwd.getpwuid(os.getuid())[0]
     self.log = self.capture_logging("juju")
     zookeeper.set_debug_level(0)
     juju_branch = ""  # get_juju_branch_url()
     self.provider = MachineProvider(
         "ec2-functional", {
             "control-bucket": "juju-test-%s" % (self.username),
             "admin-secret": "magic-beans",
             "juju-branch": juju_branch
         })
Example #4
0
    def test_default_service_factory_construction(self):
        """
        Ensure that the AWSServiceRegion gets called by the MachineProvider
        with the right arguments.  This explores the mocking which is already
        happening within EC2TestMixin.
        """
        expected_kwargs = {
            "access_key": "",
            "secret_key": "",
            "ec2_uri": "https://ec2.us-east-1.amazonaws.com",
            "s3_uri": ""
        }

        MachineProvider(self.env_name, {})
        self.assertEquals(self.service_factory_kwargs, expected_kwargs)
Example #5
0
 def test_service_factory_construction(self):
     """
     Ensure that the AWSServiceRegion gets called by the MachineProvider
     with the right arguments when they are present in the configuration.
     This explores the mocking which is already happening within
     EC2TestMixin.
     """
     config = {
         "access-key": "secret-123",
         "secret-key": "secret-abc",
         "ec2-uri": "the-ec2-uri",
         "s3-uri": "the-ec2-uri"
     }
     expected_kwargs = {}
     for key, value in config.iteritems():
         expected_kwargs[key.replace("-", "_")] = value
     MachineProvider(self.env_name, config)
     self.assertEquals(self.service_factory_kwargs, expected_kwargs)
Example #6
0
    def test_config_serialization(self):
        """
        The provider configuration can be serialized to yaml.
        """
        keys_path = self.makeFile("my-keys")

        config = {
            "access-key": "secret-123",
            "secret-key": "secret-abc",
            "authorized-keys-path": keys_path
        }

        expected_serialization = config.copy()
        expected_serialization.pop("authorized-keys-path")
        expected_serialization["authorized-keys"] = "my-keys"

        provider = MachineProvider(self.env_name, config)
        serialized = provider.get_serialization_data()
        self.assertEqual(serialized, expected_serialization)
Example #7
0
 def test_service_factory_construction_region_provides_ec2_uri(self):
     """
     The EC2 service URI can be dereferenced by region name alone.
     This explores the mocking which is already happening within
     EC2TestMixin.
     """
     config = {
         "access-key": "secret-123",
         "secret-key": "secret-abc",
         "s3-uri": "the-ec2-uri",
         "region": "eu-west-1"
     }
     expected_kwargs = {}
     for key, value in config.iteritems():
         expected_kwargs[key.replace("-", "_")] = value
     del expected_kwargs["region"]
     expected_kwargs["ec2_uri"] = "https://ec2.eu-west-1.amazonaws.com"
     MachineProvider(self.env_name, config)
     self.assertEquals(self.service_factory_kwargs, expected_kwargs)