Exemplo n.º 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)
Exemplo n.º 2
0
 def xtest_non_amazon_constraints(self):
     # Disabled because the ec2 provider requires these keys (instance-type
     # and ec2-zone)
     provider = MachineProvider("some-non-ec2-env", {
         "ec2-uri": "blah", "secret-key": "foobar", "access-key": "bar"})
     cs = yield provider.get_constraint_set()
     self.assertEquals(cs.parse([]), {
         "provider-type": "ec2",
         "ubuntu-series": None})
Exemplo n.º 3
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())
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def test_get_legacy_config_keys(self):
        provider = MachineProvider(self.env_name, {
            "access-key": "foo", "secret-key": "bar",
            # Note: these keys *will* at some stage be considered legacy keys;
            # they're included here to make sure the tests are updated when we
            # make that change.
            "default-series": "foo", "placement": "bar"})
        self.assertEquals(provider.get_legacy_config_keys(), set())

        # These keys are not valid on Amazon EC2...
        provider.config.update({
            "default-instance-type": "baz", "default-image-id": "qux"})
        self.assertEquals(provider.get_legacy_config_keys(), set((
            "default-instance-type", "default-image-id")))

        # ...but they still are when using private clouds.
        provider.config.update({"ec2-uri": "anything"})
        self.assertEquals(provider.get_legacy_config_keys(), set())
Exemplo n.º 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)
Exemplo n.º 7
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
         })
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 11
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)
Exemplo n.º 12
0
 def constraint_set(self):
     provider = MachineProvider(
         "some-ec2-env", {"access-key": "f", "secret-key": "x"})
     return provider.get_constraint_set()