Merge "Add short-report command, fix logging"

This commit is contained in:
Jenkins 2016-03-17 11:53:07 +00:00 committed by Gerrit Code Review
commit bd7a089f97
5 changed files with 41 additions and 13 deletions

10
etc/short_report.yaml Normal file
View File

@ -0,0 +1,10 @@
dump:
local:
objects:
- type: command
command:
- cat /etc/fuel_build_id
- cat /etc/fuel_build_number
- cat /etc/fuel_release
- cat /etc/fuel_openstack_version
- rpm -qa | egrep 'fuel|astute|network-checker|shotgun'

View File

@ -37,6 +37,7 @@ setuptools.setup(
'shotgun2 = shotgun.cli2:main'],
'shotgun': [
'snapshot = shotgun.cli2:SnapshotCommand',
'report = shotgun.cli2:ReportCommand'
'report = shotgun.cli2:ReportCommand',
'short-report = shotgun.cli2:ShortReportCommand',
]
})

View File

@ -13,7 +13,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
import yaml
@ -24,14 +23,12 @@ from cliff.lister import Lister
import shotgun
from shotgun.config import Config
from shotgun.logger import configure_logger
from shotgun.manager import Manager
logger = logging.getLogger(__name__)
class Base(object):
log = logging.getLogger(__name__)
def initialize_cmd(self, parsed_args):
with open(parsed_args.config, "r") as f:
self.config = Config(yaml.safe_load(f))
@ -55,19 +52,18 @@ class SnapshotCommand(Command, Base):
"""
self.initialize_cmd(parsed_args)
snapshot_path = self.manager.snapshot()
logger.info(u'Snapshot path: {0}'.format(snapshot_path))
self.log.info(u'Snapshot path: {0}'.format(snapshot_path))
def run(self, parsed_args):
"""Overriden for returning errno from exceptions"""
try:
return super(SnapshotCommand, self).run(parsed_args)
except Exception as err:
logger.error(err)
self.log.error(err)
return getattr(err, 'errno', 1)
class ReportCommand(Lister, Base):
columns = ['Host', 'Reporter', 'Report']
def get_parser(self, prog_name):
@ -84,8 +80,27 @@ class ReportCommand(Lister, Base):
return (self.columns, data)
class ShortReportCommand(Command, Base):
def get_parser(self, prog_name):
parser = super(ShortReportCommand, self).get_parser(prog_name)
parser.add_argument(
'--config',
default='/etc/shotgun/short_report.yaml',
help='Path to report config file')
return parser
def take_action(self, parsed_args):
self.initialize_cmd(parsed_args)
for line in self.manager.report():
host, reporter, report = line
if report:
if reporter:
self.app.stdout.write('{0}:\n'.format(reporter))
self.app.stdout.write(' {out}\n'.format(out=report))
def main(argv=None):
configure_logger()
return App(
description="Shotgun CLI",
version=shotgun.__version__,

View File

@ -62,12 +62,12 @@ class Manager(object):
return "{0}.tar.xz".format(self.conf.target)
def action_single(self, object, action='snapshot'):
driver = Driver.getDriver(object, self.conf)
def action_single(self, obj, action='snapshot'):
driver = Driver.getDriver(obj, self.conf)
try:
return getattr(driver, action)()
except fabric.exceptions.NetworkError:
self.conf.on_network_error(object)
self.conf.on_network_error(obj)
def report(self):
logger.debug("Making report")

View File

@ -38,6 +38,7 @@ cd %{_builddir}/%{name}-%{version} && python setup.py build
cd %{_builddir}/%{name}-%{version} && python setup.py install --single-version-externally-managed -O1 --root=$RPM_BUILD_ROOT --record=%{_builddir}/%{name}-%{version}/INSTALLED_FILES
install -d -m 755 %{buildroot}%{_sysconfdir}/shotgun
install -p -D -m 644 %{_builddir}/%{name}-%{version}/etc/report.yaml %{buildroot}%{_sysconfdir}/shotgun/report.yaml
install -p -D -m 644 %{_builddir}/%{name}-%{version}/etc/short_report.yaml %{buildroot}%{_sysconfdir}/shotgun/short_report.yaml
%clean
rm -rf $RPM_BUILD_ROOT
@ -45,3 +46,4 @@ rm -rf $RPM_BUILD_ROOT
%files -f %{_builddir}/%{name}-%{version}/INSTALLED_FILES
%defattr(-,root,root)
%{_sysconfdir}/shotgun/report.yaml
%{_sysconfdir}/shotgun/short_report.yaml