All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH 2/6] KVM test: Introducing unattended install subtest
       [not found] <447716066.1414231249352459058.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>
@ 2009-08-04  2:28 ` Michael Goldish
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Goldish @ 2009-08-04  2:28 UTC (permalink / raw)
  To: Lucas Meneghel Rodrigues; +Cc: kvm, dhuff, autotest

The test code looks nice and simple.  However, I don't think putting some
of the code in a class helps much (it doesn't hurt either).

What do you think about this alternative, replacing from 'watcher = ...':

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('', 12323))
server.listen(1)

end_time = time.time() + float(params.get("timeout", 3000))

while True:
    server.settimeout(end_time - time.time())
    try:
        (client, addr) = server.accept()
    except socket.timeout:
        server.close()
        raise error.TestFail('Timeout elapsed while waiting for install to '
                             'finish.')
    msg = client.recv(1024)
    logging.debug("Received '%s' from %s", msg, addr)
    if msg == 'done':
        logging.info('Guest reported successful installation')
        server.close()
        break
    else:
        logging.error('Got invalid string from client: %s.' % msg)

It's not necessarily shorter, but I find it a bit simpler.
The only meaningful difference here is the timeout handling.
In your original code, if a client sends anything other than 'done'
(very unlikely), the server will wait another 3000 secs.
With this code, the server will wait up to a total of 'timeout' secs
(user specified).
I find this code short and simple enough to leave outside a class,
but it's a matter of personal preference, so it's up to you.

----- Original Message -----
From: "Lucas Meneghel Rodrigues" <lmr@redhat.com>
To: autotest@test.kernel.org
Cc: kvm@vger.kernel.org, dhuff@redhat.com, "Lucas Meneghel Rodrigues" <lmr@redhat.com>
Sent: Tuesday, August 4, 2009 1:38:50 AM (GMT+0200) Auto-Detected
Subject: [PATCH 2/6] KVM test: Introducing unattended install subtest

In order to resolve the question, 'how will the guest
operating system tell the host operating system that
the unattended install process finish', we took the
simple approach and created a simple socket communication
ack process: The test instantiates a server tcp socket
on port 12323, and waits during a specified amount of time.

For guests, the vast majority of the unattended install
processes can deal with executing commands at the end of
the install process. Let's take advantage of that and
make clients tell the server about the end of the process
using simple programs that can do that. The implementation
of that strategy varies trough different operating systems.

This is the kvm test implementation code, client programs
will follow on later patches.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 client/tests/kvm/kvm.py       |    2 +
 client/tests/kvm/kvm_tests.py |   81 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 1 deletions(-)

diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py
index 070e463..db6899b 100644
--- a/client/tests/kvm/kvm.py
+++ b/client/tests/kvm/kvm.py
@@ -56,6 +56,8 @@ class kvm(test.test):
                 "linux_s3":     test_routine("kvm_tests", "run_linux_s3"),
                 "stress_boot":  test_routine("kvm_tests", "run_stress_boot"),
                 "timedrift":    test_routine("kvm_tests", "run_timedrift"),
+                "unattended_install":  test_routine("kvm_tests",
+                                                    "run_unattended_install"),
                 }
 
         # Make it possible to import modules from the test's bindir
diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py
index 9784ec9..f45fefc 100644
--- a/client/tests/kvm/kvm_tests.py
+++ b/client/tests/kvm/kvm_tests.py
@@ -1,4 +1,4 @@
-import time, os, logging, re, commands
+import time, os, logging, re, commands, socket
 from autotest_lib.client.common_lib import utils, error
 import kvm_utils, kvm_subprocess, ppm_utils, scan_results
 
@@ -9,6 +9,85 @@ KVM test definitions.
 """
 
 
+class UnattendedInstallWatcher:
+    """
+    Mechanism to verify whether an unattended guest install actually did finish.
+    It opens a TCP socket and waits until it receives a message. If it does get
+    the expected message from the guest, it will finish gracefully.
+    """
+    def __init__(self, timeout, msg):
+        self.port = 12323
+        self.buf_size = 1024
+        self.timeout = timeout
+        self.msg = msg
+
+
+    def check_answer(self, connection):
+        """
+        Verify if client has sent the correct ACK message.
+
+        @param connection: Tuple with client socket connection and address.
+        @return: True, in case the client has responded accordingly; False if
+                the string doesn't match the server expectations.
+        """
+        (client, addr) = connection
+        msg = client.recv(self.buf_size)
+        logging.debug("Received '%s' from %s", msg, addr)
+        if msg == self.msg:
+            logging.info('Guest reported successful installation')
+            return True
+        else:
+            logging.error('Got invalid string from client: %s.' % msg)
+            return False
+
+
+    def run_server(self):
+        """
+        Initializes and runs the server socket and listens for connections.
+        """
+        server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        address = ('', self.port)
+        server.bind(address)
+        server.listen(1)
+
+        while True:
+            try:
+                server.settimeout(self.timeout)
+                connection = server.accept()
+                if self.check_answer(connection):
+                    break
+            except:
+                server.close()
+                raise
+
+
+def run_unattended_install(test, params, env):
+    """
+    Unattended install test:
+    1) Starts a VM with an appropriated setup to start an unattended OS install.
+    2) Wait until the install reports to the install watcher its end.
+
+    @param test: KVM test object.
+    @param params: Dictionary with the test parameters.
+    @param env: Dictionary with test environment.
+    """
+    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
+    if not vm:
+        raise error.TestError("VM object not found in environment")
+    if not vm.is_alive():
+        raise error.TestError("VM seems to be dead; Test requires a living VM")
+
+    logging.info("Starting unattended install watch process")
+    watcher = UnattendedInstallWatcher(timeout=3000, msg='done')
+    try:
+        watcher.run_server()
+    except socket.timeout:
+        raise error.TestFail('Timeout elapsed while waiting for install to '
+                             'finish.')
+
+    logging.info("Unattended install finished successfuly")
+
+
 def run_boot(test, params, env):
     """
     KVM reboot test:
-- 
1.6.2.5

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/6] KVM test: Introducing unattended install subtest
  2009-10-09 20:40 [PATCH 1/6] KVM test: Added floppy and tftp options to qemu command Lucas Meneghel Rodrigues
@ 2009-10-09 20:40 ` Lucas Meneghel Rodrigues
  0 siblings, 0 replies; 4+ messages in thread
From: Lucas Meneghel Rodrigues @ 2009-10-09 20:40 UTC (permalink / raw)
  To: autotest; +Cc: kvm, Lucas Meneghel Rodrigues

In order to resolve the question, 'how will the guest
operating system tell the host operating system that
the unattended install process finish', we took the
simple approach and created a simple socket communication
ack process: The test instantiates a server tcp socket
on port 12323, and waits during a specified amount of time.

For guests, the vast majority of the unattended install
processes can deal with executing commands at the end of
the install process. Let's take advantage of that and
make clients tell the server about the end of the process
using simple programs that can do that. The implementation
of that strategy varies trough different operating systems.

This is the kvm test implementation code, client programs
will follow on later patches.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 client/tests/kvm/tests/unattended_install.py |   41 ++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/unattended_install.py

diff --git a/client/tests/kvm/tests/unattended_install.py b/client/tests/kvm/tests/unattended_install.py
new file mode 100644
index 0000000..1bd555f
--- /dev/null
+++ b/client/tests/kvm/tests/unattended_install.py
@@ -0,0 +1,41 @@
+import logging, time, socket
+from autotest_lib.client.common_lib import error
+import kvm_utils, kvm_test_utils
+
+
+def run_unattended_install(test, params, env):
+    """
+    Unattended install test:
+    1) Starts a VM with an appropriated setup to start an unattended OS install.
+    2) Wait until the install reports to the install watcher its end.
+
+    @param test: KVM test object.
+    @param params: Dictionary with the test parameters.
+    @param env: Dictionary with test environment.
+    """
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+
+    logging.info("Starting unattended install watch process")
+    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    server.bind(('', 12323))
+    server.listen(1)
+
+    end_time = time.time() + float(params.get("timeout", 3000))
+
+    while True:
+        server.settimeout(end_time - time.time())
+        try:
+            (client, addr) = server.accept()
+        except socket.timeout:
+            server.close()
+            raise error.TestFail('Timeout elapsed while waiting for install to '
+                                 'finish.')
+        msg = client.recv(1024)
+        logging.debug("Received '%s' from %s", msg, addr)
+        if msg == 'done':
+            logging.info('Guest reported successful installation')
+            server.close()
+            break
+        else:
+            logging.error('Got invalid string from client: %s.' % msg)
+
-- 
1.6.2.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/6] KVM test: Introducing unattended install subtest
  2009-10-06  1:03 [PATCH 1/6] KVM test: Added floppy and tftp options to qemu command Lucas Meneghel Rodrigues
@ 2009-10-06  1:03 ` Lucas Meneghel Rodrigues
  0 siblings, 0 replies; 4+ messages in thread
From: Lucas Meneghel Rodrigues @ 2009-10-06  1:03 UTC (permalink / raw)
  To: autotest; +Cc: kvm, Lucas Meneghel Rodrigues

In order to resolve the question, 'how will the guest
operating system tell the host operating system that
the unattended install process finish', we took the
simple approach and created a simple socket communication
ack process: The test instantiates a server tcp socket
on port 12323, and waits during a specified amount of time.

For guests, the vast majority of the unattended install
processes can deal with executing commands at the end of
the install process. Let's take advantage of that and
make clients tell the server about the end of the process
using simple programs that can do that. The implementation
of that strategy varies trough different operating systems.

This is the kvm test implementation code, client programs
will follow on later patches.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 client/tests/kvm/tests/unattended_install.py |   45 ++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/unattended_install.py

diff --git a/client/tests/kvm/tests/unattended_install.py b/client/tests/kvm/tests/unattended_install.py
new file mode 100644
index 0000000..60e2a35
--- /dev/null
+++ b/client/tests/kvm/tests/unattended_install.py
@@ -0,0 +1,45 @@
+import logging, time, socket
+from autotest_lib.client.common_lib import error
+import kvm_utils, kvm_test_utils
+
+
+def run_unattended_install(test, params, env):
+    """
+    Unattended install test:
+    1) Starts a VM with an appropriated setup to start an unattended OS install.
+    2) Wait until the install reports to the install watcher its end.
+
+    @param test: KVM test object.
+    @param params: Dictionary with the test parameters.
+    @param env: Dictionary with test environment.
+    """
+    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
+    if not vm:
+        raise error.TestError("VM object not found in environment")
+    if not vm.is_alive():
+        raise error.TestError("VM seems to be dead; Test requires a living VM")
+
+    logging.info("Starting unattended install watch process")
+    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    server.bind(('', 12323))
+    server.listen(1)
+
+    end_time = time.time() + float(params.get("timeout", 3000))
+
+    while True:
+        server.settimeout(end_time - time.time())
+        try:
+            (client, addr) = server.accept()
+        except socket.timeout:
+            server.close()
+            raise error.TestFail('Timeout elapsed while waiting for install to '
+                                 'finish.')
+        msg = client.recv(1024)
+        logging.debug("Received '%s' from %s", msg, addr)
+        if msg == 'done':
+            logging.info('Guest reported successful installation')
+            server.close()
+            break
+        else:
+            logging.error('Got invalid string from client: %s.' % msg)
+
-- 
1.6.2.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/6] KVM test: Introducing unattended install subtest
  2009-08-03 22:38 ` [PATCH 1/6] KVM test: Added floppy and tftp options to qemu command Lucas Meneghel Rodrigues
@ 2009-08-03 22:38   ` Lucas Meneghel Rodrigues
  0 siblings, 0 replies; 4+ messages in thread
From: Lucas Meneghel Rodrigues @ 2009-08-03 22:38 UTC (permalink / raw)
  To: autotest; +Cc: kvm, dhuff, Lucas Meneghel Rodrigues

In order to resolve the question, 'how will the guest
operating system tell the host operating system that
the unattended install process finish', we took the
simple approach and created a simple socket communication
ack process: The test instantiates a server tcp socket
on port 12323, and waits during a specified amount of time.

For guests, the vast majority of the unattended install
processes can deal with executing commands at the end of
the install process. Let's take advantage of that and
make clients tell the server about the end of the process
using simple programs that can do that. The implementation
of that strategy varies trough different operating systems.

This is the kvm test implementation code, client programs
will follow on later patches.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 client/tests/kvm/kvm.py       |    2 +
 client/tests/kvm/kvm_tests.py |   81 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 1 deletions(-)

diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py
index 070e463..db6899b 100644
--- a/client/tests/kvm/kvm.py
+++ b/client/tests/kvm/kvm.py
@@ -56,6 +56,8 @@ class kvm(test.test):
                 "linux_s3":     test_routine("kvm_tests", "run_linux_s3"),
                 "stress_boot":  test_routine("kvm_tests", "run_stress_boot"),
                 "timedrift":    test_routine("kvm_tests", "run_timedrift"),
+                "unattended_install":  test_routine("kvm_tests",
+                                                    "run_unattended_install"),
                 }
 
         # Make it possible to import modules from the test's bindir
diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py
index 9784ec9..f45fefc 100644
--- a/client/tests/kvm/kvm_tests.py
+++ b/client/tests/kvm/kvm_tests.py
@@ -1,4 +1,4 @@
-import time, os, logging, re, commands
+import time, os, logging, re, commands, socket
 from autotest_lib.client.common_lib import utils, error
 import kvm_utils, kvm_subprocess, ppm_utils, scan_results
 
@@ -9,6 +9,85 @@ KVM test definitions.
 """
 
 
+class UnattendedInstallWatcher:
+    """
+    Mechanism to verify whether an unattended guest install actually did finish.
+    It opens a TCP socket and waits until it receives a message. If it does get
+    the expected message from the guest, it will finish gracefully.
+    """
+    def __init__(self, timeout, msg):
+        self.port = 12323
+        self.buf_size = 1024
+        self.timeout = timeout
+        self.msg = msg
+
+
+    def check_answer(self, connection):
+        """
+        Verify if client has sent the correct ACK message.
+
+        @param connection: Tuple with client socket connection and address.
+        @return: True, in case the client has responded accordingly; False if
+                the string doesn't match the server expectations.
+        """
+        (client, addr) = connection
+        msg = client.recv(self.buf_size)
+        logging.debug("Received '%s' from %s", msg, addr)
+        if msg == self.msg:
+            logging.info('Guest reported successful installation')
+            return True
+        else:
+            logging.error('Got invalid string from client: %s.' % msg)
+            return False
+
+
+    def run_server(self):
+        """
+        Initializes and runs the server socket and listens for connections.
+        """
+        server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        address = ('', self.port)
+        server.bind(address)
+        server.listen(1)
+
+        while True:
+            try:
+                server.settimeout(self.timeout)
+                connection = server.accept()
+                if self.check_answer(connection):
+                    break
+            except:
+                server.close()
+                raise
+
+
+def run_unattended_install(test, params, env):
+    """
+    Unattended install test:
+    1) Starts a VM with an appropriated setup to start an unattended OS install.
+    2) Wait until the install reports to the install watcher its end.
+
+    @param test: KVM test object.
+    @param params: Dictionary with the test parameters.
+    @param env: Dictionary with test environment.
+    """
+    vm = kvm_utils.env_get_vm(env, params.get("main_vm"))
+    if not vm:
+        raise error.TestError("VM object not found in environment")
+    if not vm.is_alive():
+        raise error.TestError("VM seems to be dead; Test requires a living VM")
+
+    logging.info("Starting unattended install watch process")
+    watcher = UnattendedInstallWatcher(timeout=3000, msg='done')
+    try:
+        watcher.run_server()
+    except socket.timeout:
+        raise error.TestFail('Timeout elapsed while waiting for install to '
+                             'finish.')
+
+    logging.info("Unattended install finished successfuly")
+
+
 def run_boot(test, params, env):
     """
     KVM reboot test:
-- 
1.6.2.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-09 20:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <447716066.1414231249352459058.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com>
2009-08-04  2:28 ` [PATCH 2/6] KVM test: Introducing unattended install subtest Michael Goldish
2009-10-09 20:40 [PATCH 1/6] KVM test: Added floppy and tftp options to qemu command Lucas Meneghel Rodrigues
2009-10-09 20:40 ` [PATCH 2/6] KVM test: Introducing unattended install subtest Lucas Meneghel Rodrigues
  -- strict thread matches above, loose matches on Subject: below --
2009-10-06  1:03 [PATCH 1/6] KVM test: Added floppy and tftp options to qemu command Lucas Meneghel Rodrigues
2009-10-06  1:03 ` [PATCH 2/6] KVM test: Introducing unattended install subtest Lucas Meneghel Rodrigues
2009-08-03 22:38 KVM test: Unattended install support Lucas Meneghel Rodrigues
2009-08-03 22:38 ` [PATCH 1/6] KVM test: Added floppy and tftp options to qemu command Lucas Meneghel Rodrigues
2009-08-03 22:38   ` [PATCH 2/6] KVM test: Introducing unattended install subtest Lucas Meneghel Rodrigues

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.