Merge "Make some tweaks to swift logging"
This commit is contained in:
commit
1cf2c55d43
@ -113,9 +113,10 @@ class PublishUILogToSwiftAction(base.TripleOAction):
|
||||
next_filename = '{}.{}'.format(
|
||||
constants.TRIPLEO_UI_LOG_FILENAME, next_suffix)
|
||||
try:
|
||||
data = swift.get_object(self.logging_container,
|
||||
constants.TRIPLEO_UI_LOG_FILENAME)[1]
|
||||
swift.put_object(self.logging_container, next_filename, data)
|
||||
swift.copy_object(
|
||||
self.logging_container,
|
||||
constants.TRIPLEO_UI_LOG_FILENAME,
|
||||
"/%s/%s" % (self.logging_container, next_filename))
|
||||
swift.delete_object(self.logging_container,
|
||||
constants.TRIPLEO_UI_LOG_FILENAME)
|
||||
except swiftexceptions.ClientException as err:
|
||||
@ -124,14 +125,14 @@ class PublishUILogToSwiftAction(base.TripleOAction):
|
||||
|
||||
def run(self, context):
|
||||
swift = self.get_object_client(context)
|
||||
swiftutils.get_or_create_container(swift, self.logging_container)
|
||||
swiftutils.create_container(swift, self.logging_container)
|
||||
self._rotate(swift)
|
||||
|
||||
try:
|
||||
old_contents = swift.get_object(
|
||||
self.logging_container,
|
||||
constants.TRIPLEO_UI_LOG_FILENAME)[1]
|
||||
new_contents = old_contents + '\n' + self.logging_data
|
||||
new_contents = "%s\n%s" % (old_contents, self.logging_data)
|
||||
except swiftexceptions.ClientException:
|
||||
LOG.debug(
|
||||
"There is no existing logging data, starting a new file.")
|
||||
|
@ -62,9 +62,6 @@ class PublishUILogToSwiftActionTest(base.TestCase):
|
||||
self.swift.head_object.return_value = {
|
||||
'content-length': 1
|
||||
}
|
||||
self.swift.get_container.return_value = (
|
||||
{}, []
|
||||
)
|
||||
data = 'data'
|
||||
action = logging_to_swift.PublishUILogToSwiftAction(
|
||||
data, self.container)
|
||||
@ -73,7 +70,7 @@ class PublishUILogToSwiftActionTest(base.TestCase):
|
||||
self.swift.get_object.assert_called_once()
|
||||
self.swift.head_object.assert_called_once()
|
||||
self.swift.put_object.assert_called_once()
|
||||
self.swift.get_container.assert_called_once()
|
||||
self.swift.put_container.assert_called_once()
|
||||
|
||||
def test_rotate(self):
|
||||
self.swift.head_object.return_value = {
|
||||
|
@ -403,16 +403,13 @@ class ExportPlanActionTest(base.TestCase):
|
||||
get_object_mock_calls = [
|
||||
mock.call(self.plan, tf) for tf in self.template_files
|
||||
]
|
||||
get_container_mock_calls = [
|
||||
mock.call(self.plan),
|
||||
mock.call('plan-exports')
|
||||
]
|
||||
|
||||
action = plan.ExportPlanAction(self.plan, self.delete_after,
|
||||
self.exports_container)
|
||||
action.run(self.ctx)
|
||||
|
||||
self.swift.get_container.assert_has_calls(get_container_mock_calls)
|
||||
self.swift.get_container.assert_called_once_with(self.plan)
|
||||
self.swift.put_container.assert_called_once_with('plan-exports')
|
||||
self.swift.get_object.assert_has_calls(
|
||||
get_object_mock_calls, any_order=True)
|
||||
self.swift.put_object.assert_called_once()
|
||||
|
@ -15,8 +15,6 @@
|
||||
|
||||
import mock
|
||||
|
||||
from swiftclient import exceptions as swiftexceptions
|
||||
|
||||
from tripleo_common.tests import base
|
||||
from tripleo_common.utils import swift as swift_utils
|
||||
|
||||
@ -78,12 +76,6 @@ class SwiftTest(base.TestCase):
|
||||
self.swiftclient.get_container.assert_called()
|
||||
self.swiftclient.delete_object.assert_not_called()
|
||||
|
||||
def test_get_or_create_container_create(self):
|
||||
self.swiftclient.get_container.side_effect = \
|
||||
swiftexceptions.ClientException('error')
|
||||
swift_utils.get_or_create_container(self.swiftclient, 'abc')
|
||||
def test_create_container(self):
|
||||
swift_utils.create_container(self.swiftclient, 'abc')
|
||||
self.swiftclient.put_container.assert_called()
|
||||
|
||||
def test_get_or_create_container_get(self):
|
||||
swift_utils.get_or_create_container(self.swiftclient, 'abc')
|
||||
self.swiftclient.put_container.assert_not_called()
|
||||
|
@ -18,8 +18,6 @@ import logging
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from swiftclient import exceptions as swiftexceptions
|
||||
|
||||
from tripleo_common import constants
|
||||
from tripleo_common.utils import tarball
|
||||
|
||||
@ -77,12 +75,10 @@ def download_container(swiftclient, container, dest):
|
||||
f.write(contents)
|
||||
|
||||
|
||||
def get_or_create_container(swiftclient, container):
|
||||
try:
|
||||
return swiftclient.get_container(container)
|
||||
except swiftexceptions.ClientException:
|
||||
LOG.debug("Container %s doesn't exist, creating...", container)
|
||||
return swiftclient.put_container(container)
|
||||
def create_container(swiftclient, container):
|
||||
# If the container already exists, it will return 202 and everything will
|
||||
# work
|
||||
swiftclient.put_container(container)
|
||||
|
||||
|
||||
def create_and_upload_tarball(swiftclient,
|
||||
@ -94,7 +90,7 @@ def create_and_upload_tarball(swiftclient,
|
||||
"""Create a tarball containing the tmp_dir and upload it to Swift."""
|
||||
headers = {'X-Delete-After': delete_after}
|
||||
|
||||
get_or_create_container(swiftclient, container)
|
||||
create_container(swiftclient, container)
|
||||
|
||||
with tempfile.NamedTemporaryFile() as tmp_tarball:
|
||||
tarball.create_tarball(tmp_dir, tmp_tarball.name, tarball_options)
|
||||
|
Loading…
Reference in New Issue
Block a user