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

ovirt-engine-hyper-upgrade: general improvements #1

Merged
merged 44 commits into from Nov 1, 2017
Merged

ovirt-engine-hyper-upgrade: general improvements #1

merged 44 commits into from Nov 1, 2017

Conversation

dougsland
Copy link
Contributor

The initial draft code was impressive but required some additional work. This patch is a re-factoring of initial code.

Helps clarify the code flow.
Options added initially:
    --check-upgrade-rhv-4-0
    --check-upgrade-rhv-4-1
    --list-enabled-repos
In case system have no repo available, display the msg
to users.
Yedidyah Bar David
Merge check_rhv_40_repos and check_rhv_41_repos into
check_rhv_repos
- Add docstring to get_enabled_repos
- replace """ to '''
Requires: engine-setup, engine-upgrade-check and
          subscription-manager
Show programs output and commands being executed.
- add print_err
- print messaging
- return returncode for the execute_cmd

%build
%if 0%{?enable_autotools}
autoreconf -if
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 add autogen.sh, perhaps use it? If there is a specific reason not to, perhaps add a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In spec file we usually don't use helper scripts.

Copy link
Member

@didib didib left a comment

Choose a reason for hiding this comment

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

Some comments inline.

Also, is this tool intended to handle also hosts, one day? If not, why do we have texts with 'RHV environments' instead of just 'engine' (or 'RHV Manager', which is how it's called in RHV)?

@@ -76,6 +76,10 @@ make %{?_smp_mflags}
%install
make %{?_smp_mflags} install DESTDIR="%{buildroot}"

%post
ln -sf %{_sbindir}/ovirt-engine-hyper-upgrade %{_sbindir}/engine-hyper-upgrade
ln -sf %{_mandir}/man8/ovirt-engine-hyper-upgrade.* %{_mandir}/man8/engine-hyper-upgrade.8.gz
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can come up with a single name? We didn't commit to current name anywhere. Can even create a new repo with a new name and migrate. If you add this link because we also have 'engine-setup', then I am not sure that is a good choice either...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added because of engine-setup. @didib @sandrobonazzola please let me know if you guys want a different name. Having 'ovirt-'engine-hyper-upgade because of upstream and engine-hyper-upgrade because of downstream is fine for me. On the other hand, the tool is downstream only but lives upstream.

@@ -16,16 +16,35 @@ import argparse
import subprocess
import sys

from enum import Enum
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 python-enum34 to the spec file. This is already an indirect dep of the engine, should be ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In python 2.7 contain enum, don't think it's required @didib.

cat /etc/redhat-release

Red Hat Enterprise Linux Server release 7.4 (Maipo)

python

Python 2.7.5 (default, May 3 2017, 07:55:04)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

from enum import Enum
class MsgType(Enum):
... INFO = 1
... WARNING = 2
... ERROR = 3
...
print MsgType.INFO
MsgType.INFO

type
INFO - The message will be print as green
WARNING - The message will be print as yellow
fh = logging.FileHandler("/var/log/engine-hyper-upgrade.log")
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps make this optional, can be done later

Perhaps have in a constant somewhere for now

Perhaps put in /var/log/ovirt-engine/something

Perhaps name ovirt-engine-hyper-upgrade.log, or rename also the package and binary. See other comment about symlinks...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a const and under /var/log/ovirt-engine but about the name I will wait a suggestion from you guys :-)

WARNING - The message will be print as yellow
fh = logging.FileHandler("/var/log/engine-hyper-upgrade.log")
fh.setLevel(logging.DEBUG)
debug_fmt = logging.Formatter("%(asctime)s %(message)s",
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps use same format as the engine, which wasn't very easy to get right.
otopi was even more complex, because I need to have it running well without being installed from rpm (so without extra deps).

For engine, check: packaging/pythonlib/ovirt_engine/service.py

See also: https://bugzilla.redhat.com/1408193


if type == MsgType.ERROR:
self.logger.error((
"\033[91m[ ERROR ]\033[00m {msg}".format(msg=message)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps keep the escape sequence strings in named variables/constants for better readability

except subprocess.CalledProcessError as e:
sys.exit(2)
# We need to parse output of subscription-manager, using check_output
for line in execute_cmd_check_output(rhsm_cmd).splitlines():
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather have:

output = something
for line in output.splitlines():

So that if the command fails, it's easier to understand that from the stack trace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

elif version == '4.1':
required = set(self.RHV_41_REPOS)
else:
raise RuntimeError('Version parameters not supported!')
Copy link
Member

Choose a reason for hiding this comment

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

I think text is not ideal.

Perhaps use something like check_releases you have below in a global dict/list and use that. Then you can simplify above code, and make the error message something like:

'Detected RHV version is {v}. This tool only supports the following versions: {versions}'.format(...)

or something like that.

output = execute_cmd(
self.SUBSCRIPTION_MANAGER_GET_ENABLED_REPOS
).splitlines()
rhsm_cmd = list(self.SUBSCRIPTION_MANAGER)
Copy link
Member

Choose a reason for hiding this comment

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

IIUC you use 'list' because you want a copy. Some other options:

  1. Use plain '+' - execute_cmd(self.SUBSCRIPTION_MANAGER + ['repos', '--list-enabled'])

  2. Or a more efficient variation 'itertools.chain' - probably an overkill here - https://stackoverflow.com/questions/1720421/how-to-concatenate-two-lists-in-python

  3. If you do want to copy, I know it's common to use a slice, self.SUBSCRIPTION_MANAGER[:] . Not sure why it's common, but someone tested and said it's the fastest: https://stackoverflow.com/questions/2612802/how-to-clone-or-copy-a-list/2612990#2612990

yum_update_engine_cmd = list(self.YUM_UPDATE_CMD)
yum_update_engine_cmd.extend(
'ovirt-engine-setup*',
'ovirt-engine-dwh-setup*'
Copy link
Member

Choose a reason for hiding this comment

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

I think we used to suggest:

yum update ovirt-engine*setup*

At the time, this included also ovirt-engine-reports. Perhaps today these are identical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

During my tests if I don't update ovirt-engine-dwh-setup* the engine-setup fails requiring an updated ovirt-engine-dwh-setup package. @didib

)

parser.add_argument(
'--check-upgrade-rhv-4-1',
action='store_true',
help='Check if RHV 4.1 channels have upgrade available',
help='Check if RHV 4.1 channels have zstream upgrade available. '
'Also enable 4.2 channels',
Copy link
Member

Choose a reason for hiding this comment

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

Are the texts for these two options intentionally different?

I am not sure we need them. Perhaps better to have a single option "--upgrade-to-version=", default to 4.2 currently. Not sure I understand the intention, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure about if we intend to support hosts in the future, @didib @sandrobonazzola might know.

@dougsland
Copy link
Contributor Author

Talked with Didi via irc, merging now and I will work in the comments in separate patch.

@dougsland dougsland merged commit d349345 into oVirt:master Nov 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants