Skip to content
This repository has been archived by the owner on Feb 9, 2022. It is now read-only.

Support log for ansible-disaster-recovery #43

Merged
merged 16 commits into from May 17, 2018
Merged

Conversation

maorlipchuk
Copy link

@maorlipchuk maorlipchuk commented Apr 24, 2018

  1. Changes in vault and Configparse usages to avoid any missing dependecies in RHEL installation.
  2. dr-play.yml will be copied to "files" folder to be used for the ovirt-dr script.
  3. Introduce the use of log file in ovirt-dr script.
    The script default location and level is configured in the dr.conf
    Default location is /var/log/ovirt-dr/ovirt-dr.log and default level is "DEBUG"
    The user can override it with --log-file and --log-level
    If no log file will be specified stdout will be used to print the output.

@machacekondra
Copy link
Contributor

Why not do it inside build.sh script? I've created it so it's simpler then using Makefile.

@maorlipchuk maorlipchuk force-pushed the makefile_additions branch 2 times, most recently from 0c72857 to 13591f1 Compare May 2, 2018 02:16
@maorlipchuk maorlipchuk changed the title Support log file for ansible-disaster-recovery in Makefile Support scripts and log file for ansible-disaster-recovery in build.sh May 2, 2018
build.sh Outdated
@@ -6,12 +6,14 @@ RPM_RELEASE="0.1.$MILESTONE.$(date -u +%Y%m%d%H%M%S)"

ROLE_NAME="oVirt.disaster-recovery"
PACKAGE_NAME="ovirt-ansible-disaster-recovery"
PREFIX=/usr/local
LOG_NAME="ovirt-dr"
PPREFIX=/usr/local
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it's renamed to PPREFIX? I think it's typo, no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh damn, you are right, will fix

build.sh Outdated

cp -pR defaults/ $PKG_DATA_DIR
cp -pR library/ $PKG_DATA_DIR
cp -pR meta/ $PKG_DATA_DIR
cp -pR tasks/ $PKG_DATA_DIR
cp -pR examples/ $PKG_DATA_DIR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We store examples in /usr/share/doc for other roles, jut FYI, if you want to have it also in /usr/share/ you can, up to you.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would want to use the ansible play there in the script, that is why I'm copying it.
I will try to copy only the play without the entire example folder.
Let me know if you have a better idea

@maorlipchuk maorlipchuk force-pushed the makefile_additions branch 3 times, most recently from 34c8c50 to ff101d5 Compare May 2, 2018 09:53
Copy link
Contributor

@machacekondra machacekondra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the DR RPM should create directory /var/log/ovirt-dr/. Like follows:

install -d /var/log/ovirt-dr -m 755

and in spec file:

%dir /var/log/ovirt-dr

Then the DR script should always create file disaster-recovery-{timestamp} in /var/log/ovirt-dr directory. Maybe configure logrotate for it? Depends how often it will be used. Or if you think it's better to use single log file and append to it, I am OK with it, but be sure it's simple for users to understand the log, where which part starts/ends.

If you follow your current way don't forget to add %ghost %log_file_path to spec file, and verify it's OK with rpm --verify command.

@machacekondra
Copy link
Contributor

@mwperina

@maorlipchuk maorlipchuk force-pushed the makefile_additions branch 6 times, most recently from 50630b7 to 9af6fc3 Compare May 2, 2018 18:35
build.sh Outdated
@@ -6,12 +6,14 @@ RPM_RELEASE="0.1.$MILESTONE.$(date -u +%Y%m%d%H%M%S)"

ROLE_NAME="oVirt.disaster-recovery"
PACKAGE_NAME="ovirt-ansible-disaster-recovery"
LOG_NAME="ovirt-dr"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to put logs into /var/log/ovirt-dr then please provide logrotate setup similarly as we do in engine:

https://github.com/oVirt/ovirt-engine/blob/master/packaging/sys-etc/logrotate.d/ovirt-engine.in

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the file,
please let me know if there is anything more that should be addressed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to add dependency to logrotate, replace relative paths inside it (please take a look at GENERATED list and its usage in engine Makefile [1]) and install it into /etc/logrotate.d [2].

[1] https://github.com/oVirt/ovirt-engine/blob/master/Makefile#L211
[2] https://github.com/oVirt/ovirt-engine/blob/master/ovirt-engine.spec.in#L990

@maorlipchuk maorlipchuk force-pushed the makefile_additions branch 2 times, most recently from 3e0b864 to 8ba4e48 Compare May 2, 2018 18:58
@maorlipchuk
Copy link
Author

Why do we need to add %dir /var/log/ovirt-dr in the spec file?

If I add it the build fails, since it refers '/var/log/ovirt-dr' as a relative path, see below:
18:59:53 [check-patch.el7.x86_64] error: Directory not found: /home/jenkins/workspace/oVirt_ovirt-ansible-disaster-recovery_standard-check-pr/ovirt-ansible-disaster-recovery/rpmbuild/BUILDROOT/ovirt-ansible-disaster-recovery-0.4-0.1.master.20180502185951.el7.centos.x86_64/var/log/ovirt-dr

@maorlipchuk maorlipchuk force-pushed the makefile_additions branch 5 times, most recently from 6800434 to c0b737c Compare May 3, 2018 05:09
@@ -0,0 +1,8 @@
"@PKG_LOG_DIR/LOG_NAME@/ovirt-dr.log" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are you replacing @PKG_LOG_DIR/LOG_NAME@ with /var/log/ovirt-dr? Also why is there only single log file? Where are you going to log multiple concurrent invocations of a role from single machine?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what I've defined in the spec, I will try to do that with '/var/log/ovirt-dr'
I've tried to follow how ovirt-engine works, should I do it like this:
"/var/log/ovirt-dr"/*.log

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok if the file is located here: logrotate.d/ovirt-dr.in

@@ -26,10 +26,12 @@ This Ansible role provide funtionality to perform disaster recovery for oVirt en
export PKG_DATA_DIR_ORIG=%{_datadir}/%{ansible_roles_dir}/%{roleprefix}%{rolename}
export PKG_DATA_DIR=%{buildroot}$PKG_DATA_DIR_ORIG
export PKG_DOC_DIR=%{buildroot}%{_pkgdocdir}
install -dm 755 "$PKG_LOG_DIR/$LOG_NAME/$LOG_NAME.log"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add Requires: logrotate spec file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add it like this
Requires: logrotate.d/ovirt-dr.in
or is that enough:
Requires: logrotate

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use Requires: logrotate, logrotate is a package name

Copy link
Contributor

@machacekondra machacekondra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking of it, I think the best approach for DR would be to have --log-file and --log-level command line options, instead of persistent log directory maybe it will be even more simple. But I will leave this decision on you.

@maorlipchuk
Copy link
Author

maorlipchuk commented May 10, 2018

Changed the log to be compatible with your suggestion:
/tmp/ovirt-dr-{timestamp}.log

I haven't understood how would you want me to use the callback plugins.
I've tried to change the ansible.cfg to work with the following configuration (see [1]), but stdout has not been changed.

[1]
# Use the YAML callback plugin.
stdout_callback = yaml
# Use the stdout_callback when running ad-hoc commands.
bin_ansible_callbacks = True

build.sh Outdated
@@ -44,6 +44,7 @@ install() {
cp -pR library/ $PKG_DATA_DIR
cp -pR meta/ $PKG_DATA_DIR
cp -pR tasks/ $PKG_DATA_DIR
cp examples/dr_play.yml $PKG_DATA_DIR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this in doc directory already, isn't it enought? Or why is it needed also in usr/share?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted the user to be able to also change this.
It is good that this will be in the doc directory so the user will be able to see that as an example.
For the user to use that as part of the scripts I thought it will be more appropriate to be copied to the DATA_DIR directory so the user will be able to manipulate it.
If you think it is redundant I can remove it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in /usr/share so his changes will be overriten by update anyway. So the correct use case is to copy the file from doc to some of his directory or /etc...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that to keep it simple we can also use the dr_play from the examples.
So I will just change the dr.conf to point to the example dr_play which is in the doc directory

@@ -3,4 +3,4 @@
hosts: localhost
connection: local
roles:
- oVirt.disaster-recovery
- ovirt-ansible-disaster-recovery
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use oVirt.disaster-recovery

files/dr.conf Outdated
[generate_vars]
site=http://engine.example.com/ovirt-engine/api
site=http://localhost:8080/ovirt-engine/api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use engine.example.com

FailOver().run('dr.conf', '/var/log/ovirt-dr/ovirt-dr.log')
level = logging.getLevelName("DEBUG")
conf = 'dr.conf'
log = '/var/log/ovirt-dr/ovirt-dr.log'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This directory don't exist so it should be here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only be used for testing or if the user will try to run that script directly instead through the ovirt-dr script (which initialize the log file)
I can change this to be /tmp if you think it is neccessery.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, but anyone other testing it, will fail, because he won't have that directory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in fail-over should create that directory if it doesn't exists.
but to keep it simple I will change it to /tmp

@maorlipchuk maorlipchuk force-pushed the makefile_additions branch 5 times, most recently from 9379082 to 317eb02 Compare May 17, 2018 00:43
Copy link
Member

@mwperina mwperina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase before merging

Maor Lipchuk added 15 commits May 17, 2018 11:03
Change dr-play location in dr.conf and change vault location
Using attribute 'ExtendedInterpolation' is not compatible for
configparser.
If it is being used from RHEL 7.4 the following exception
is being thrown:
Traceback (most recent call last):
  File "./ovirt-dr", line 145, in <module>
    main(sys.argv[1:])
  File "./ovirt-dr", line 28, in main
    action, conf_file, log_file, log_level = _init_vars(argv)
  File "./ovirt-dr", line 88, in _init_vars
    log_file, log_level = _get_log_conf(conf_file, log_file, log_level)
  File "./ovirt-dr", line 101, in _get_log_conf
    settings._interpolation = configparser.ExtendedInterpolation()
AttributeError: 'module' object has no attribute 'ExtendedInterpolation'

Therefore to make the code compatible for RHEL as well, instead of
using configparser, we use SafeConfigParser from ConfigParser.
Configure the report file name to be passed as an argument when
running the ovirt_dr script on failover and failback.
@maorlipchuk maorlipchuk merged commit d4b6fc3 into master May 17, 2018
@sandrobonazzola sandrobonazzola deleted the makefile_additions branch February 5, 2020 07:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants