Merge "Added negative tests for server"
diff --git a/etc/logging.conf.sample b/etc/logging.conf.sample
index 685dd36..3b468f1 100644
--- a/etc/logging.conf.sample
+++ b/etc/logging.conf.sample
@@ -1,5 +1,5 @@
 [loggers]
-keys=root,tempest
+keys=root,tempest,tempest_stress
 
 [handlers]
 keys=file,syslog,devel
@@ -16,6 +16,11 @@
 handlers=file
 qualname=tempest
 
+[logger_tempest_stress]
+level=INFO
+handlers=file,devel
+qualname=tempest.stress
+
 [handler_file]
 class=FileHandler
 level=DEBUG
diff --git a/etc/tempest.conf.sample b/etc/tempest.conf.sample
index 12a57db..f1aaa07 100644
--- a/etc/tempest.conf.sample
+++ b/etc/tempest.conf.sample
@@ -10,6 +10,8 @@
 # lock/semaphore base directory
 lock_path=/tmp
 
+default_log_levels=tempest.stress=INFO,amqplib=WARN,sqlalchemy=WARN,boto=WARN,suds=INFO,keystone=INFO,eventlet.wsgi.server=WARN
+
 [identity]
 # This section contains configuration options that a variety of Tempest
 # test clients use when authenticating with different user/tenant
diff --git a/tempest/stress/README.rst b/tempest/stress/README.rst
index 31642b0..7c180f6 100644
--- a/tempest/stress/README.rst
+++ b/tempest/stress/README.rst
@@ -23,7 +23,8 @@
 	target_controller = "hostname or ip of controller node (for nova-manage)
 	log_check_interval = "time between checking logs for errors (default 60s)"
 
-
+To activate logging on your console please make sure that you activate `use_stderr`
+in tempest.conf or use the default `logging.conf.sample` file.
 
 Running the sample test
 -----------------------
diff --git a/tempest/stress/cleanup.py b/tempest/stress/cleanup.py
index bfcf34f..1bd9485 100644
--- a/tempest/stress/cleanup.py
+++ b/tempest/stress/cleanup.py
@@ -17,13 +17,16 @@
 #    limitations under the License.
 
 from tempest import clients
+from tempest.openstack.common import log as logging
+
+LOG = logging.getLogger(__name__)
 
 
-def cleanup(logger):
+def cleanup():
     admin_manager = clients.AdminManager()
 
     _, body = admin_manager.servers_client.list_servers({"all_tenants": True})
-    logger.debug("Cleanup::remove %s servers" % len(body['servers']))
+    LOG.info("Cleanup::remove %s servers" % len(body['servers']))
     for s in body['servers']:
         try:
             admin_manager.servers_client.delete_server(s['id'])
@@ -37,7 +40,7 @@
             pass
 
     _, keypairs = admin_manager.keypairs_client.list_keypairs()
-    logger.debug("Cleanup::remove %s keypairs" % len(keypairs))
+    LOG.info("Cleanup::remove %s keypairs" % len(keypairs))
     for k in keypairs:
         try:
             admin_manager.keypairs_client.delete_keypair(k['name'])
@@ -45,7 +48,7 @@
             pass
 
     _, floating_ips = admin_manager.floating_ips_client.list_floating_ips()
-    logger.debug("Cleanup::remove %s floating ips" % len(floating_ips))
+    LOG.info("Cleanup::remove %s floating ips" % len(floating_ips))
     for f in floating_ips:
         try:
             admin_manager.floating_ips_client.delete_floating_ip(f['id'])
@@ -53,13 +56,13 @@
             pass
 
     _, users = admin_manager.identity_client.get_users()
-    logger.debug("Cleanup::remove %s users" % len(users))
+    LOG.info("Cleanup::remove %s users" % len(users))
     for user in users:
         if user['name'].startswith("stress_user"):
             admin_manager.identity_client.delete_user(user['id'])
 
     _, tenants = admin_manager.identity_client.list_tenants()
-    logger.debug("Cleanup::remove %s tenants" % len(tenants))
+    LOG.info("Cleanup::remove %s tenants" % len(tenants))
     for tenant in tenants:
         if tenant['name'].startswith("stress_tenant"):
             admin_manager.identity_client.delete_tenant(tenant['id'])
@@ -69,7 +72,7 @@
 
     _, snaps = admin_manager.snapshots_client.\
         list_snapshots({"all_tenants": True})
-    logger.debug("Cleanup::remove %s snapshots" % len(snaps))
+    LOG.info("Cleanup::remove %s snapshots" % len(snaps))
     for v in snaps:
         try:
             admin_manager.snapshots_client.\
@@ -85,7 +88,7 @@
             pass
 
     _, vols = admin_manager.volumes_client.list_volumes({"all_tenants": True})
-    logger.debug("Cleanup::remove %s volumes" % len(vols))
+    LOG.info("Cleanup::remove %s volumes" % len(vols))
     for v in vols:
         try:
             admin_manager.volumes_client.\
diff --git a/tempest/stress/driver.py b/tempest/stress/driver.py
index d9b95e0..efc57a9 100644
--- a/tempest/stress/driver.py
+++ b/tempest/stress/driver.py
@@ -12,7 +12,6 @@
 #    See the License for the specific language governing permissions and
 #    limitations under the License.
 
-import logging
 import multiprocessing
 import signal
 import time
@@ -22,30 +21,12 @@
 from tempest.common.utils.data_utils import rand_name
 from tempest import exceptions
 from tempest.openstack.common import importutils
+from tempest.openstack.common import log as logging
 from tempest.stress import cleanup
 
 admin_manager = clients.AdminManager()
 
-# setup logging to file
-logging.basicConfig(
-    format='%(asctime)s %(process)d %(name)-20s %(levelname)-8s %(message)s',
-    datefmt='%m-%d %H:%M:%S',
-    filename="stress.debug.log",
-    filemode="w",
-    level=logging.DEBUG,
-)
-
-# define a Handler which writes INFO messages or higher to the sys.stdout
-_console = logging.StreamHandler()
-_console.setLevel(logging.INFO)
-# set a format which is simpler for console use
-format_str = '%(asctime)s %(process)d %(name)-20s: %(levelname)-8s %(message)s'
-_formatter = logging.Formatter(format_str)
-# tell the handler to use this format
-_console.setFormatter(_formatter)
-# add the handler to the root logger
-logger = logging.getLogger('tempest.stress')
-logger.addHandler(_console)
+LOG = logging.getLogger(__name__)
 processes = []
 
 
@@ -90,7 +71,7 @@
         if not errors:
             return None
         if len(errors) > 0:
-            logger.error('%s: %s' % (node, errors))
+            LOG.error('%s: %s' % (node, errors))
             return errors
     return None
 
@@ -147,13 +128,13 @@
                                           tenant_name=tenant_name)
 
             test_obj = importutils.import_class(test['action'])
-            test_run = test_obj(manager, logger, max_runs, stop_on_error)
+            test_run = test_obj(manager, max_runs, stop_on_error)
 
             kwargs = test.get('kwargs', {})
             test_run.setUp(**dict(kwargs.iteritems()))
 
-            logger.debug("calling Target Object %s" %
-                         test_run.__class__.__name__)
+            LOG.debug("calling Target Object %s" %
+                      test_run.__class__.__name__)
 
             mp_manager = multiprocessing.Manager()
             shared_statistic = mp_manager.dict()
@@ -208,24 +189,24 @@
     sum_fails = 0
     sum_runs = 0
 
-    logger.info("Statistics (per process):")
+    LOG.info("Statistics (per process):")
     for process in processes:
         if process['statistic']['fails'] > 0:
             had_errors = True
         sum_runs += process['statistic']['runs']
         sum_fails += process['statistic']['fails']
-        logger.info(" Process %d (%s): Run %d actions (%d failed)" %
-                    (process['p_number'],
-                     process['action'],
-                     process['statistic']['runs'],
+        LOG.info(" Process %d (%s): Run %d actions (%d failed)" %
+                 (process['p_number'],
+                  process['action'],
+                  process['statistic']['runs'],
                      process['statistic']['fails']))
-    logger.info("Summary:")
-    logger.info("Run %d actions (%d failed)" %
-                (sum_runs, sum_fails))
+    LOG.info("Summary:")
+    LOG.info("Run %d actions (%d failed)" %
+             (sum_runs, sum_fails))
 
     if not had_errors:
-        logger.info("cleaning up")
-        cleanup.cleanup(logger)
+        LOG.info("cleaning up")
+        cleanup.cleanup()
     if had_errors:
         return 1
     else:
diff --git a/tempest/stress/stressaction.py b/tempest/stress/stressaction.py
index ab09adc..3719841 100644
--- a/tempest/stress/stressaction.py
+++ b/tempest/stress/stressaction.py
@@ -17,12 +17,15 @@
 import signal
 import sys
 
+from tempest.openstack.common import log as logging
+
 
 class StressAction(object):
 
-    def __init__(self, manager, logger, max_runs=None, stop_on_error=False):
+    def __init__(self, manager, max_runs=None, stop_on_error=False):
+        full_cname = self.__module__ + "." + self.__class__.__name__
+        self.logger = logging.getLogger(full_cname)
         self.manager = manager
-        self.logger = logger
         self.max_runs = max_runs
         self.stop_on_error = stop_on_error
 
diff --git a/tempest/stress/tools/cleanup.py b/tempest/stress/tools/cleanup.py
index b6a26cd..3885ba0 100755
--- a/tempest/stress/tools/cleanup.py
+++ b/tempest/stress/tools/cleanup.py
@@ -14,15 +14,6 @@
 #    See the License for the specific language governing permissions and
 #    limitations under the License.
 
-import logging
-
 from tempest.stress import cleanup
 
-_console = logging.StreamHandler()
-_console.setLevel(logging.DEBUG)
-# add the handler to the root logger
-logger = logging.getLogger('tempest.stress.cleanup')
-logger.addHandler(logging.StreamHandler())
-logger.setLevel(logging.DEBUG)
-
-cleanup.cleanup(logger)
+cleanup.cleanup()