ovirt-engine-hyper-upgrade: general improvements #1
Conversation
Using shell=True can be a security hazard. More info: https://docs.python.org/2/library/subprocess.html#frequently-used-arguments
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 '''
remove duplicate code
Requires: engine-setup, engine-upgrade-check and
subscription-manager
Show programs output and commands being executed.
engine-setup and yum update requires
- add print_err - print messaging - return returncode for the execute_cmd
it's not used at all
- no need to use print_err, cmds will show the message - extend yum update cmd
- use subprocess.check_output to get id from subscription-manager and parse - remove list-enabled-repos (not needed)
|
|
||
| %build | ||
| %if 0%{?enable_autotools} | ||
| autoreconf -if |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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)?
ovirt-engine-hyper-upgrade.spec.in
Outdated
| @@ -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 | |||
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
src/ovirt-engine-hyper-upgrade
Outdated
| @@ -16,16 +16,35 @@ import argparse | |||
| import subprocess | |||
| import sys | |||
|
|
|||
| from enum import Enum | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
src/ovirt-engine-hyper-upgrade
Outdated
| 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") |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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 :-)
src/ovirt-engine-hyper-upgrade
Outdated
| 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", |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
src/ovirt-engine-hyper-upgrade
Outdated
| 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(): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
ovirt-engine-hyper-upgrade.py
Outdated
| elif version == '4.1': | ||
| required = set(self.RHV_41_REPOS) | ||
| else: | ||
| raise RuntimeError('Version parameters not supported!') |
There was a problem hiding this comment.
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.
ovirt-engine-hyper-upgrade.py
Outdated
| output = execute_cmd( | ||
| self.SUBSCRIPTION_MANAGER_GET_ENABLED_REPOS | ||
| ).splitlines() | ||
| rhsm_cmd = list(self.SUBSCRIPTION_MANAGER) |
There was a problem hiding this comment.
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:
-
Use plain '+' - execute_cmd(self.SUBSCRIPTION_MANAGER + ['repos', '--list-enabled'])
-
Or a more efficient variation 'itertools.chain' - probably an overkill here - https://stackoverflow.com/questions/1720421/how-to-concatenate-two-lists-in-python
-
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
src/ovirt-engine-hyper-upgrade
Outdated
| yum_update_engine_cmd = list(self.YUM_UPDATE_CMD) | ||
| yum_update_engine_cmd.extend( | ||
| 'ovirt-engine-setup*', | ||
| 'ovirt-engine-dwh-setup*' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
ovirt-engine-hyper-upgrade.py
Outdated
| ) | ||
|
|
||
| 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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Talked with Didi via irc, merging now and I will work in the comments in separate patch. |
The initial draft code was impressive but required some additional work. This patch is a re-factoring of initial code.