Add each command to the history file
Change-Id: I1e93305426dd94dbbcc8ca70f446dae4a1fa0434
This commit is contained in:
parent
f7c0214aee
commit
53d06b7f52
tripleoclient
command.py
tests
utils.pyv1
baremetal.pycontainer_image.pyovercloud_config.pyovercloud_credentials.pyovercloud_delete.pyovercloud_deploy.pyovercloud_execute.pyovercloud_image.pyovercloud_netenv_validate.pyovercloud_node.pyovercloud_parameters.pyovercloud_plan.pyovercloud_profiles.pyovercloud_raid.pyovercloud_roles.pyovercloud_support.pyovercloud_update.pyundercloud.py
29
tripleoclient/command.py
Normal file
29
tripleoclient/command.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# Copyright 2017 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from osc_lib.command import command
|
||||||
|
|
||||||
|
|
||||||
|
from tripleoclient import utils
|
||||||
|
|
||||||
|
|
||||||
|
class Command(command.Command):
|
||||||
|
|
||||||
|
def run(self, parsed_args):
|
||||||
|
utils.store_cli_param(self.cmd_name, parsed_args)
|
||||||
|
super(Command, self).run(parsed_args)
|
||||||
|
|
||||||
|
|
||||||
|
class Lister(Command, command.Lister):
|
||||||
|
pass
|
@ -13,13 +13,13 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import datetime
|
||||||
import mock
|
import mock
|
||||||
from mock import call
|
|
||||||
import os.path
|
import os.path
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
import yaml
|
import yaml
|
||||||
@ -588,7 +588,8 @@ class TestStoreCliParam(TestCase):
|
|||||||
def test_fail_to_create_file(self, mock_exists, mock_mkdir):
|
def test_fail_to_create_file(self, mock_exists, mock_mkdir):
|
||||||
mock_exists.return_value = False
|
mock_exists.return_value = False
|
||||||
mock_mkdir.side_effect = OSError()
|
mock_mkdir.side_effect = OSError()
|
||||||
self.assertRaises(OSError, utils.store_cli_param, self.args)
|
command = "undercloud install"
|
||||||
|
self.assertRaises(OSError, utils.store_cli_param, command, self.args)
|
||||||
|
|
||||||
@mock.patch('os.path.isdir')
|
@mock.patch('os.path.isdir')
|
||||||
@mock.patch('os.path.exists')
|
@mock.patch('os.path.exists')
|
||||||
@ -597,18 +598,31 @@ class TestStoreCliParam(TestCase):
|
|||||||
mock_isdir.return_value = False
|
mock_isdir.return_value = False
|
||||||
self.assertRaises(exceptions.InvalidConfiguration,
|
self.assertRaises(exceptions.InvalidConfiguration,
|
||||||
utils.store_cli_param,
|
utils.store_cli_param,
|
||||||
self.args)
|
"overcloud deploy", self.args)
|
||||||
|
|
||||||
@mock.patch('six.moves.builtins.open')
|
|
||||||
@mock.patch('os.path.isdir')
|
@mock.patch('os.path.isdir')
|
||||||
@mock.patch('os.path.exists')
|
@mock.patch('os.path.exists')
|
||||||
def test_write_cli_param(self, mock_exists, mock_isdir, mock_open):
|
def test_write_cli_param(self, mock_exists, mock_isdir):
|
||||||
history_path = os.path.join(os.path.expanduser("~"), '.tripleo')
|
history_path = os.path.join(os.path.expanduser("~"), '.tripleo')
|
||||||
mock_exists.return_value = True
|
mock_exists.return_value = True
|
||||||
mock_isdir.return_value = True
|
mock_isdir.return_value = True
|
||||||
utils.store_cli_param(self.args)
|
mock_file = mock.mock_open()
|
||||||
expected_call = [call("%s/history" % history_path, 'a')]
|
|
||||||
mock_open.assert_has_calls(expected_call)
|
class ArgsFake(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.a = 1
|
||||||
|
|
||||||
|
dt = datetime.datetime(2017, 11, 22)
|
||||||
|
with mock.patch("six.moves.builtins.open", mock_file):
|
||||||
|
with mock.patch('tripleoclient.utils.datetime') as mock_date:
|
||||||
|
mock_date.datetime.now.return_value = dt
|
||||||
|
utils.store_cli_param("overcloud plan list", ArgsFake())
|
||||||
|
|
||||||
|
expected_call = [
|
||||||
|
mock.call("%s/history" % history_path, 'a'),
|
||||||
|
mock.call().write('2017-11-22 00:00:00 overcloud-plan-list a=1 \n')
|
||||||
|
]
|
||||||
|
mock_file.assert_has_calls(expected_call, any_order=True)
|
||||||
|
|
||||||
@mock.patch('six.moves.builtins.open')
|
@mock.patch('six.moves.builtins.open')
|
||||||
@mock.patch('os.path.isdir')
|
@mock.patch('os.path.isdir')
|
||||||
@ -617,4 +631,4 @@ class TestStoreCliParam(TestCase):
|
|||||||
mock_exists.return_value = True
|
mock_exists.return_value = True
|
||||||
mock_isdir.return_value = True
|
mock_isdir.return_value = True
|
||||||
mock_open.side_effect = IOError()
|
mock_open.side_effect = IOError()
|
||||||
self.assertRaises(IOError, utils.store_cli_param, self.args)
|
self.assertRaises(IOError, utils.store_cli_param, "command", self.args)
|
||||||
|
@ -64,9 +64,14 @@ def write_overcloudrc(stack_name, overcloudrcs, config_directory='.'):
|
|||||||
os.chmod(rcv3path, 0o600)
|
os.chmod(rcv3path, 0o600)
|
||||||
|
|
||||||
|
|
||||||
def store_cli_param(parsed_args):
|
def store_cli_param(command_name, parsed_args):
|
||||||
"""write the cli parameters into an history file"""
|
"""write the cli parameters into an history file"""
|
||||||
|
|
||||||
|
# The command name is the part after "openstack" with spaces. Switching
|
||||||
|
# to "-" makes it easier to read. "openstack undercloud install" will be
|
||||||
|
# stored as "undercloud-install" for example.
|
||||||
|
command_name = command_name.replace(" ", "-")
|
||||||
|
|
||||||
history_path = os.path.join(os.path.expanduser("~"), '.tripleo')
|
history_path = os.path.join(os.path.expanduser("~"), '.tripleo')
|
||||||
if not os.path.exists(history_path):
|
if not os.path.exists(history_path):
|
||||||
try:
|
try:
|
||||||
@ -83,7 +88,7 @@ def store_cli_param(parsed_args):
|
|||||||
used_args = ', '.join('%s=%s' % (key, value)
|
used_args = ', '.join('%s=%s' % (key, value)
|
||||||
for key, value in args.items())
|
for key, value in args.items())
|
||||||
history.write(' '.join([str(datetime.datetime.now()),
|
history.write(' '.join([str(datetime.datetime.now()),
|
||||||
used_args]))
|
str(command_name), used_args, "\n"]))
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
messages = "Unable to write into TripleO history file: "
|
messages = "Unable to write into TripleO history file: "
|
||||||
"{0}, {1}".format(history_path, e)
|
"{0}, {1}".format(history_path, e)
|
||||||
|
@ -21,9 +21,9 @@ import simplejson
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import ironic_inspector_client
|
import ironic_inspector_client
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient import exceptions
|
from tripleoclient import exceptions
|
||||||
from tripleoclient import utils
|
from tripleoclient import utils
|
||||||
from tripleoclient.workflows import baremetal
|
from tripleoclient.workflows import baremetal
|
||||||
|
@ -23,7 +23,6 @@ import tempfile
|
|||||||
|
|
||||||
from heatclient.common import template_utils
|
from heatclient.common import template_utils
|
||||||
from heatclient.common import utils as heat_utils
|
from heatclient.common import utils as heat_utils
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib import exceptions as oscexc
|
from osc_lib import exceptions as oscexc
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
import requests
|
import requests
|
||||||
@ -33,6 +32,7 @@ import yaml
|
|||||||
from tripleo_common.image import image_uploader
|
from tripleo_common.image import image_uploader
|
||||||
from tripleo_common.image import kolla_builder
|
from tripleo_common.image import kolla_builder
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient import constants
|
from tripleoclient import constants
|
||||||
from tripleoclient import utils
|
from tripleoclient import utils
|
||||||
|
|
||||||
|
@ -13,11 +13,11 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
|
|
||||||
from tripleo_common.utils import config as ooo_config
|
from tripleo_common.utils import config as ooo_config
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
|
|
||||||
|
|
||||||
class DownloadConfig(command.Command):
|
class DownloadConfig(command.Command):
|
||||||
"""Download Overcloud Config"""
|
"""Download Overcloud Config"""
|
||||||
|
@ -12,8 +12,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from osc_lib.command import command
|
from tripleoclient import command
|
||||||
|
|
||||||
from tripleoclient import utils
|
from tripleoclient import utils
|
||||||
from tripleoclient.workflows import deployment
|
from tripleoclient.workflows import deployment
|
||||||
|
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib import exceptions as oscexc
|
from osc_lib import exceptions as oscexc
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
from osc_lib import utils as osc_utils
|
from osc_lib import utils as osc_utils
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient import utils
|
from tripleoclient import utils
|
||||||
from tripleoclient.workflows import plan_management
|
from tripleoclient.workflows import plan_management
|
||||||
from tripleoclient.workflows import stack_management
|
from tripleoclient.workflows import stack_management
|
||||||
|
@ -27,12 +27,12 @@ import yaml
|
|||||||
|
|
||||||
from heatclient.common import template_utils
|
from heatclient.common import template_utils
|
||||||
from heatclient import exc as hc_exc
|
from heatclient import exc as hc_exc
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib import exceptions as oscexc
|
from osc_lib import exceptions as oscexc
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
from swiftclient.exceptions import ClientException
|
from swiftclient.exceptions import ClientException
|
||||||
from tripleo_common import update
|
from tripleo_common import update
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient import constants
|
from tripleoclient import constants
|
||||||
from tripleoclient import exceptions
|
from tripleoclient import exceptions
|
||||||
from tripleoclient import utils
|
from tripleoclient import utils
|
||||||
@ -928,7 +928,6 @@ class DeployOvercloud(command.Command):
|
|||||||
sc_logger.setLevel(logging.CRITICAL)
|
sc_logger.setLevel(logging.CRITICAL)
|
||||||
|
|
||||||
self._validate_args(parsed_args)
|
self._validate_args(parsed_args)
|
||||||
utils.store_cli_param(parsed_args)
|
|
||||||
|
|
||||||
stack = utils.get_stack(self.orchestration_client, parsed_args.stack)
|
stack = utils.get_stack(self.orchestration_client, parsed_args.stack)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import logging
|
|||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from osc_lib.command import command
|
from tripleoclient import command
|
||||||
|
|
||||||
|
|
||||||
class RemoteExecute(command.Command):
|
class RemoteExecute(command.Command):
|
||||||
|
@ -21,13 +21,13 @@ import re
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib import exceptions
|
from osc_lib import exceptions
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
from prettytable import PrettyTable
|
from prettytable import PrettyTable
|
||||||
|
|
||||||
from tripleo_common.image import build
|
from tripleo_common.image import build
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient import utils as plugin_utils
|
from tripleoclient import utils as plugin_utils
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,11 +19,12 @@ import logging
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import ipaddress
|
import ipaddress
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
import six
|
import six
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
|
|
||||||
|
|
||||||
class ValidateOvercloudNetenv(command.Command):
|
class ValidateOvercloudNetenv(command.Command):
|
||||||
"""Validate the network environment file."""
|
"""Validate the network environment file."""
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient import constants
|
from tripleoclient import constants
|
||||||
from tripleoclient.exceptions import InvalidConfiguration
|
from tripleoclient.exceptions import InvalidConfiguration
|
||||||
from tripleoclient import utils as oooutils
|
from tripleoclient import utils as oooutils
|
||||||
|
@ -16,9 +16,9 @@ import os
|
|||||||
import simplejson
|
import simplejson
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient import exceptions
|
from tripleoclient import exceptions
|
||||||
from tripleoclient import utils
|
from tripleoclient import utils
|
||||||
from tripleoclient.workflows import base
|
from tripleoclient.workflows import base
|
||||||
|
@ -14,10 +14,10 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
from six.moves.urllib import request
|
from six.moves.urllib import request
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient import constants
|
from tripleoclient import constants
|
||||||
from tripleoclient import exceptions
|
from tripleoclient import exceptions
|
||||||
from tripleoclient import utils
|
from tripleoclient import utils
|
||||||
|
@ -14,9 +14,9 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient import exceptions
|
from tripleoclient import exceptions
|
||||||
from tripleoclient import utils
|
from tripleoclient import utils
|
||||||
|
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient.workflows import baremetal
|
from tripleoclient.workflows import baremetal
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,9 +19,10 @@ import collections
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from osc_lib.command import command
|
|
||||||
from tripleo_common.exception import NotFound
|
from tripleo_common.exception import NotFound
|
||||||
from tripleo_common.utils import roles as rolesutils
|
from tripleo_common.utils import roles as rolesutils
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient.constants import TRIPLEO_HEAT_TEMPLATES
|
from tripleoclient.constants import TRIPLEO_HEAT_TEMPLATES
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from tripleoclient.workflows import support
|
|
||||||
|
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
|
from tripleoclient.workflows import support
|
||||||
|
|
||||||
|
|
||||||
class ReportExecute(command.Command):
|
class ReportExecute(command.Command):
|
||||||
"""Run sosreport on selected servers."""
|
"""Run sosreport on selected servers."""
|
||||||
|
@ -18,10 +18,10 @@ import os
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
from osc_lib.command import command
|
|
||||||
from osc_lib.i18n import _
|
from osc_lib.i18n import _
|
||||||
from oslo_concurrency import processutils
|
from oslo_concurrency import processutils
|
||||||
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient import constants
|
from tripleoclient import constants
|
||||||
from tripleoclient import exceptions
|
from tripleoclient import exceptions
|
||||||
from tripleoclient import utils as oooutils
|
from tripleoclient import utils as oooutils
|
||||||
|
@ -20,7 +20,8 @@ import logging
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from openstackclient.i18n import _
|
from openstackclient.i18n import _
|
||||||
from osc_lib.command import command
|
|
||||||
|
from tripleoclient import command
|
||||||
from tripleoclient import utils
|
from tripleoclient import utils
|
||||||
from tripleoclient.v1 import undercloud_config
|
from tripleoclient.v1 import undercloud_config
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user