Use FileFormatBasedSerializer for 'upload' method of VIPAction
Base fuel client serializer (which is used for v1 of codebase) while reading given file assumes that it is supplied w/o file format extension and adds it to passed string before actual read operation. This leads to obvious error in case of VIP related actions as full path to a file is used as argument for those. Using FileFormatBasedSerializer eliminates such issue as its 'read_from_file' methods operates on given path as it is. Change-Id: I0a954f6c5c91130a0e3cd5e0dfa896b2adc2d6d3 Closes-Bug: #1553241
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
|
||||
from fuelclient.cli.actions.base import Action
|
||||
import fuelclient.cli.arguments as Args
|
||||
from fuelclient.cli import serializers
|
||||
from fuelclient.objects.environment import Environment
|
||||
|
||||
|
||||
@@ -25,6 +26,10 @@ class VIPAction(Action):
|
||||
|
||||
def __init__(self):
|
||||
super(VIPAction, self).__init__()
|
||||
# NOTE(aroma): 'serializer' attribute for action objects is
|
||||
# overwritten while building parser object
|
||||
# (fuelclient.cli.parser.Parser)
|
||||
self.file_serializer = serializers.FileFormatBasedSerializer()
|
||||
self.args = (
|
||||
Args.get_env_arg(required=True),
|
||||
Args.get_upload_file_arg("Upload changed VIP configuration "
|
||||
@@ -48,7 +53,7 @@ class VIPAction(Action):
|
||||
env = Environment(params.env)
|
||||
vips_data = env.read_vips_data_from_file(
|
||||
file_path=params.upload,
|
||||
serializer=self.serializer
|
||||
serializer=self.file_serializer
|
||||
)
|
||||
env.set_vips_data(vips_data)
|
||||
print("VIP configuration uploaded.")
|
||||
|
||||
@@ -166,12 +166,18 @@ class TestVIPActions(base.UnitTestCase):
|
||||
mopen().__enter__().read.return_value = MANY_VIPS_YAML
|
||||
self.m_request.get('/api/v1/clusters/1/', json=ENV_OUTPUT)
|
||||
request_put = self.m_request.put(url, json={})
|
||||
|
||||
file_path = 'vips.yaml'
|
||||
|
||||
with mock.patch('fuelclient.objects.environment.os') as env_os:
|
||||
env_os.path.exists.return_value = True
|
||||
self.execute('fuel vip --env 1 --upload vips_1.yaml'.split())
|
||||
self.execute(['fuel', 'vip', '--env', '1', '--upload', file_path])
|
||||
self.assertEqual(env_os.path.exists.call_count, 1)
|
||||
self.assertEqual(request_put.call_count, 1)
|
||||
self.assertIn(url, request_put.last_request.url)
|
||||
# FileFormatBasedSerializer.read_from_file must not modify given
|
||||
# file path string
|
||||
self.assertEqual(file_path, mopen.call_args[0][0])
|
||||
|
||||
def test_vips_upload_bad_path(self, mos, mopen):
|
||||
with mock.patch('sys.stderr', new=six.moves.cStringIO()) as mstderr:
|
||||
|
||||
Reference in New Issue
Block a user