def test_get_temp_url_no_account_key(self):
        swift_client = mock.MagicMock()
        swift_client.url = ("http://fake-host.com:8080/v1/AUTH_demo")
        head_account = {}

        def post_account(data):
            head_account.update(data)

        swift_client.head_account = mock.Mock(return_value=head_account)
        swift_client.post_account = post_account

        self.assertNotIn('x-account-meta-temp-url-key', head_account)
        deployment_utils.create_temp_url(swift_client, 'bar', 60, 'foo')
        self.assertIn('x-account-meta-temp-url-key', head_account)
    def test_get_temp_url_no_account_key(self):
        swift_client = mock.MagicMock()
        swift_client.url = ("http://fake-host.com:8080/v1/AUTH_demo")
        head_account = {}

        def post_account(data):
            head_account.update(data)

        swift_client.head_account = mock.Mock(return_value=head_account)
        swift_client.post_account = post_account

        self.assertNotIn('x-account-meta-temp-url-key', head_account)
        deployment_utils.create_temp_url(swift_client, 'bar', 60, 'foo')
        self.assertIn('x-account-meta-temp-url-key', head_account)
Example #3
0
    def run(self, context):
        heat = self.get_orchestration_client(context)
        swift_client = self.get_object_client(context)

        swift_url = deployment_utils.create_temp_url(swift_client,
                                                     self.name,
                                                     self.timeout)
        container_name, object_name = \
            self._extract_container_object_from_swift_url(swift_url)

        params = self._build_sc_params(swift_url)
        config = heat.software_configs.create(**params)

        sd = heat.software_deployments.create(
            tenant_id='asdf',  # heatclient requires this
            config_id=config.id,
            server_id=self.server_id,
            action=self.action,
            status='IN_PROGRESS'
        )

        body = self._wait_for_data(container_name, object_name, context)

        # cleanup
        try:
            sd.delete()
            config.delete()
            swift_client.delete_object(container_name, object_name)
            swift_client.delete_container(container_name)
        except Exception as err:
            LOG.error("Error cleaning up heat deployment resources.", err)

        error = None
        if not body:
            body_json = {}
            error = "Timeout for heat deployment '%s'" % self.name
        else:
            body_json = json.loads(body)
            if body_json['deploy_status_code'] != 0:
                error = "Heat deployment failed for '%s'" % self.name

        if error:
            LOG.error(error)

        return actions.Result(data=body_json, error=error)
    def test_create_temp_url(self):
        swift_client = mock.MagicMock()
        swift_client.url = ("http://fake-host.com:8080/v1/AUTH_demo")
        swift_client.head_account = mock.Mock(return_value={
            'x-account-meta-temp-url-key': '123456'})
        swift_client.post_account = mock.Mock()

        uuid_pattern = ('[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB]'
                        '[a-f0-9]{3}-[a-f0-9]{12}')
        url = deployment_utils.create_temp_url(swift_client, 'bar', 60)
        self.assertFalse(swift_client.post_account.called)
        regexp = (r"http://fake-host.com:8080/v1/AUTH_demo/bar-%s"
                  r"/%s\?temp_url_sig=[0-9a-f]{40}&"
                  r"temp_url_expires=[0-9]{10}" % (uuid_pattern, uuid_pattern))
        self.assertThat(url, matchers.MatchesRegex(regexp))

        timeout = int(url.split('=')[-1])
        self.assertTrue(timeout < 2147483647)
    def test_create_temp_url(self):
        swift_client = mock.MagicMock()
        swift_client.url = ("http://fake-host.com:8080/v1/AUTH_demo")
        swift_client.head_account = mock.Mock(return_value={
            'x-account-meta-temp-url-key': '123456'})
        swift_client.post_account = mock.Mock()

        uuid_pattern = ('[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB]'
                        '[a-f0-9]{3}-[a-f0-9]{12}')
        url = deployment_utils.create_temp_url(swift_client, 'bar', 60)
        self.assertFalse(swift_client.post_account.called)
        regexp = ("http://fake-host.com:8080/v1/AUTH_demo/bar-%s"
                  "/%s\?temp_url_sig=[0-9a-f]{40}&"
                  "temp_url_expires=[0-9]{10}" % (uuid_pattern, uuid_pattern))
        self.assertThat(url, matchers.MatchesRegex(regexp))

        timeout = int(url.split('=')[-1])
        self.assertTrue(timeout < 2147483647)