Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify configuration #713

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 75 additions & 2 deletions lago/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from lago.config import config
from lago import (log_utils, workdir as lago_workdir, utils, lago_ansible)
from lago.utils import (in_prefix, with_logging, LagoUserException)
from lago.verify_configuration import (fix_configuration, check_configuration, check_user, check_directory,validate_status, VerifyLagoStatus)

LOGGER = logging.getLogger('cli')
in_lago_prefix = in_prefix(
Expand Down Expand Up @@ -67,7 +68,6 @@
'$PWD/.lago'
),
metavar='WORKDIR',
type=os.path.abspath,
Copy link
Member

Choose a reason for hiding this comment

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

Why did you remove this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't be removed

nargs='?',
)
@lago.plugins.cli.cli_plugin_add_argument(
Expand Down Expand Up @@ -751,7 +751,6 @@ def do_copy_to_vm(prefix, host, remote_path, local_path, **kwargs):
def do_collect(prefix, output, no_skip, **kwargs):
prefix.collect_artifacts(output, ignore_nopath=not no_skip)


@lago.plugins.cli.cli_plugin(
help='Run scripts that install necessary RPMs and configuration'
)
Expand All @@ -760,6 +759,79 @@ def do_collect(prefix, output, no_skip, **kwargs):
def do_deploy(prefix, **kwargs):
prefix.deploy()

@lago.plugins.cli.cli_plugin(
help='Verify that the machine runninh Lago is well configured and configure if needed'
)
@lago.plugins.cli.cli_plugin_add_argument(
'--username',
'-u',
help='Which user needs to be configured',
Copy link
Member

Choose a reason for hiding this comment

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

We can add a default here:
getpass.getuser() will return the name of the current user.

action='store',
)

@lago.plugins.cli.cli_plugin_add_argument(
'--envs-dir',
'-e',
dest='envs_dir',
help='Which directory the qemu has access permissions',
default="/var/lib/lago",
Copy link
Member

Choose a reason for hiding this comment

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

This switch is about where the user is going to create the lago envs.
In /var/lib/lago we store files that are being shared between the different envs.
I would use here os.curdir, or take this value from lago.conf.

type=os.path.abspath,
action='store',
)

@lago.plugins.cli.cli_plugin_add_argument(
'--verify',
'-v',
help='Return report that describes which configurations are OK, and which are not.',
action='store_true',
)
@in_lago_prefix
@with_logging
def do_setup(
prefix, username, envs_dir, verify, **kwargs
Copy link
Member

Choose a reason for hiding this comment

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

in_lago_prefix returns an object that represents a lago environment. In this case, we still don't have a lago env, so it's not needed.

):
msg_error = []
if (username):
if (check_user(username)):
msg_error.append("Username doesn't exists " + username)
else:
username = os.getenv("SUDO_USER") or os.getenv("USER")

if (envs_dir):
if (check_directory(envs_dir)):
msg_error.append("Directory doesn't exists "+ envs_dir)

if ( msg_error ):
msg_error_str = '\n'.join(msg_error)
LOGGER.error("%s", msg_error_str)
sys.exit(1)

config_dict = check_configuration(username,envs_dir)
(verify_status,list_not_configure) = validate_status(config_dict)
verify_lago = VerifyLagoStatus(username,envs_dir,config_dict,verify_status)

if (verify):
verify_lago.displayLagoStatus(True)
if verify_status:
sys.exit(0)
else:
sys.exit(2)
else:
if (os.getuid() != 0):
print("Please use 'sudo', you need adminstrator permissions for configuration")
sys.exit(1)
else:
Copy link
Member

Choose a reason for hiding this comment

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

There is no need for an else here. If the first condition was true, the program exited.

fix_configuration(username,envs_dir,config_dict)
config_dict = check_configuration(username,envs_dir)
(verify_status,list_not_configure) = validate_status(config_dict)
verify_lago.fixLagoConfiguration(config_dict,verify_status)

if verify_status:
sys.exit(0)
else:
LOGGER.error("Problem to configure: %s", str(list_not_configure))
verify_lago.displayLagoStatus(False)
sys.exit(2)

@lago.plugins.cli.cli_plugin(help="Dump configuration file")
@lago.plugins.cli.cli_plugin_add_argument(
Expand All @@ -768,6 +840,7 @@ def do_deploy(prefix, **kwargs):
action='store_true',
default=False,
)

def do_generate(verbose, **kwargs):
print(config.get_ini(incl_unset=verbose))

Expand Down
Loading