提交 566a42c0 编写于 作者: C Cleber Rosa

VM Plugin: make --vm-hostname optional by attempting to find IP address

By leveraging the `avocado.core.virt.VM.ip_address` method, let's make
the `--vm-hostname` optional. If the IP address can not be found, then
ask users to manually provide it.

If the user has a VM running, or has had it running a "while" back,
chances are pretty high Avocado will be able to find it's IP address.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 f6de76e8
......@@ -47,8 +47,10 @@ class RunVM(plugin.Plugin):
help=('Specify hypervisor URI driver '
'connection. Current: %s' %
default_hypervisor_uri))
self.vm_parser.add_argument('--vm-hostname',
help='Specify VM hostname to login')
self.vm_parser.add_argument('--vm-hostname', default=None,
help=('Specify VM hostname to login. By '
'default it attempts to automatically'
' find the VM IP address.'))
self.vm_parser.add_argument('--vm-username', default=username,
help='Specify the username to login on VM')
self.vm_parser.add_argument('--vm-password',
......@@ -89,7 +91,6 @@ class RunVM(plugin.Plugin):
return True
def activate(self, app_args):
if self._check_required_args(app_args, 'vm_domain',
('vm_domain', 'vm_hostname')):
if self._check_required_args(app_args, 'vm_domain', ('vm_domain',)):
self.vm_parser.set_defaults(remote_result=VMTestResult,
test_runner=RemoteTestRunner)
......@@ -106,11 +106,6 @@ class VMTestResult(RemoteTestResult):
def setup(self):
# Super called after VM is found and initialized
if self.args.vm_hostname is None:
e_msg = ('Please set Virtual Machine hostname with option '
'--vm-hostname.')
self.stream.notify(event='error', msg=e_msg)
raise exceptions.JobError(e_msg)
self.stream.notify(event='message', msg="DOMAIN : %s"
% self.args.vm_domain)
self.vm = virt.vm_connect(self.args.vm_domain,
......@@ -122,6 +117,14 @@ class VMTestResult(RemoteTestResult):
e_msg = "Could not start VM '%s'" % self.args.vm_domain
raise exceptions.JobError(e_msg)
assert self.vm.domain.isActive() is not False
# If hostname wasn't given, let's try to find out the IP address
if self.args.vm_hostname is None:
self.args.vm_hostname = self.vm.ip_address()
if self.args.vm_hostname is None:
e_msg = ("Could not find the IP address for VM '%s'. Please "
"set it explicitly with --vm-hostname" %
self.args.vm_domain)
raise exceptions.JobError(e_msg)
if self.args.vm_cleanup is True:
self.vm.create_snapshot()
if self.vm.snapshot is None:
......
......@@ -96,7 +96,8 @@ when using the ``run`` command in the Avocado command line tool::
--vm-domain VM_DOMAIN
Specify domain name (Virtual Machine name)
--vm-hostname VM_HOSTNAME
Specify VM hostname to login
Specify VM hostname to login. By default it attempts
to automatically find the VM IP address.
--vm-username VM_USERNAME
Specify the username to login on VM
--vm-password VM_PASSWORD
......@@ -108,6 +109,11 @@ From these options, you are normally going to use `--vm-domain`,
`--vm-hostname` and `--vm-username` in case you did set up your VM with
password-less SSH connection (through SSH keys).
If you have the VM already running, or have had it running and it a
"while" back, you can probably skip the `--vm-hostname` option as
Avocado will attempt to find out the VM IP address based on the MAC
address and ARP table.
Virtual Machine Setup
---------------------
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册