cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [1/7] add more libs
Date Tue, 23 Sep 2014 01:10:25 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/pytest b155b8aea -> d002c52a1


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d002c52a/tools/marvin/marvin/pytest/VM.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/pytest/VM.py b/tools/marvin/marvin/pytest/VM.py
deleted file mode 100644
index 086d8d8..0000000
--- a/tools/marvin/marvin/pytest/VM.py
+++ /dev/null
@@ -1,104 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-import pytest
-
-from marvin.lib.common import get_zone,get_domain,get_template
-from marvin.lib.base import ServiceOffering,Account,VirtualMachine
-
-
-@pytest.fixture()
-def test_client(request):
-    if request.cls is not None:
-        return request.node.cls.testClient
-    else:
-        return request.node.testClient
-
-@pytest.fixture()
-def zone(test_client):
-    apiClient = test_client.getApiClient()
-    zone = get_zone(apiClient, test_client.getZoneForTests())
-    return zone
-
-@pytest.fixture()
-def tiny_service_offering(test_client, zone):
-    apiClient = test_client.getApiClient()
-
-    params = {
-        "name": "Tiny Instance",
-        "displaytext": "Tiny Instance",
-        "cpunumber": 1,
-        "cpuspeed": 100,
-        "memory": 128,
-        }
-
-    if zone.localstorageenabled:
-        params["storagetype"] = "local"
-
-    return ServiceOffering.create(apiClient, params)
-
-@pytest.fixture()
-def domain(test_client):
-    apiClient = test_client.getApiClient()
-    return get_domain(apiClient)
-
-@pytest.fixture()
-def account(test_client, domain):
-    params = {
-        "email": "test-account@test.com",
-        "firstname": "test",
-        "lastname": "test",
-        "username": "test-account",
-        "password": "password"
-    }
-
-    apiclient = test_client.getApiClient()
-
-    return Account.create(apiclient, params, domainid=domain.id)
-
-@pytest.fixture()
-def template(test_client, zone):
-    return get_template(
-        test_client.getApiClient(),
-        zone.id,
-        "CentOS 5.6 (64-bit)"
-    )
-
-@pytest.fixture()
-def vm(test_client, account, template, tiny_service_offering, zone):
-    params = {
-        "displayname": "!#@#@fjdkjf",
-        "username": "root",
-        "password": "password",
-        "ssh_port": 22,
-        "hypervisor": "XenServer",
-        "privateport": 22,
-        "publicport": 22,
-        "protocol": 'TCP',
-    }
-    virtual_machine = VirtualMachine.create(
-        test_client.getApiClient(),
-        params,
-        zoneid=zone.id,
-        templateid=template.id,
-        accountid=account.name,
-        domainid=account.domainid,
-        serviceofferingid=tiny_service_offering.id,
-        mode=zone.networktype
-    )
-
-    return virtual_machine

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d002c52a/tools/marvin/marvin/pytest/fixtures/__init__.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/pytest/fixtures/__init__.py b/tools/marvin/marvin/pytest/fixtures/__init__.py
new file mode 100644
index 0000000..0871bc1
--- /dev/null
+++ b/tools/marvin/marvin/pytest/fixtures/__init__.py
@@ -0,0 +1 @@
+__author__ = 'edison'

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d002c52a/tools/marvin/marvin/pytest/fixtures/vm.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/pytest/fixtures/vm.py b/tools/marvin/marvin/pytest/fixtures/vm.py
new file mode 100644
index 0000000..8994463
--- /dev/null
+++ b/tools/marvin/marvin/pytest/fixtures/vm.py
@@ -0,0 +1,61 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import pytest
+
+from marvin.lib.utils.zone import getCurrentZone
+from marvin.lib.utils.domain import getCurrentDomain
+from marvin.lib.utils.serviceoffering import createTinyServiceOffering
+from marvin.lib.utils.account import createAccount
+from marvin.lib.utils.template import getDefaultUservmTemplate
+from marvin.lib.utils.vm import createvm
+@pytest.fixture()
+def test_client(request):
+    if request.cls is not None:
+        return request.node.cls.testClient
+    else:
+        return request.node.testClient
+
+@pytest.fixture()
+def api_client(test_client):
+    return test_client.getApiClient()
+
+@pytest.fixture()
+def zone(api_client):
+    return getCurrentZone(api_client)
+
+@pytest.fixture()
+def tiny_service_offering(api_client, zone):
+    return createTinyServiceOffering(api_client,zone)
+
+@pytest.fixture()
+def domain(api_client):
+    return getCurrentDomain(api_client)
+
+@pytest.fixture()
+def account(api_client, domain):
+    return createAccount(api_client,domain)
+
+@pytest.fixture()
+def template(api_client):
+    return getDefaultUservmTemplate(api_client)
+
+@pytest.fixture()
+def vm(api_client, request):
+    vm = createvm(api_client)
+    request.addfinalizer(vm.delete)
+    return vm

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d002c52a/tools/marvin/marvin/pytest/pytest_marvin_plugin.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/pytest/pytest_marvin_plugin.py b/tools/marvin/marvin/pytest/pytest_marvin_plugin.py
index 46b91a3..906bfa9 100644
--- a/tools/marvin/marvin/pytest/pytest_marvin_plugin.py
+++ b/tools/marvin/marvin/pytest/pytest_marvin_plugin.py
@@ -18,29 +18,13 @@ import pytest
 import os
 
 from marvin.utils import initTestClass,getMarvin
-from .VM import (vm,tiny_service_offering,template,test_client,account,domain,zone)
-
+from .fixtures.vm import vm,api_client,test_client,zone,domain,tiny_service_offering,template,domain,account
 def pytest_configure(config):
     config.addinivalue_line("markers",
         "tags(name): tag tests")
 
     marvin_init_tags()
 
-def pytest_collection_finish(session):
-    units = []
-    for item in session.items:
-        if item.instance is None and item.cls is None:
-            units.append(item.nodeid)
-        elif item.instance is not None:
-            instance = item.instance
-            name = instance.__module__ + ":" + instance.__class__.__name__
-            units.append(name)
-        else:
-            name = item.cls
-            units.append(name)
-
-    print units
-
 g_marvin_filter = {
     "tags":[],
 }
@@ -51,14 +35,17 @@ def tobool(str):
     else:
         return False
 def marvin_init_tags():
-    tags = os.environ.get("MARVIN_TAGS", "advanced,required_hardware=false").split(",")
+    tags = os.environ.get("MARVIN_TAGS", "advanced,required_hardware=false,hypervisors=simulator").split(",")
     global g_marvin_filter
     for t in tags:
         if t.startswith("required_hardware"):
             g_marvin_filter["required_hardware"] = t.split("=")[1]
+        elif t.startswith("hypervisors"):
+            g_marvin_filter["hypervisors"] = [t.split("=")[1]]
         else:
             g_marvin_filter["tags"].append(t)
 
+
 def pytest_runtest_setup(item):
     global g_marvin_filter
     attrmarker = item.get_marker("tags")
@@ -68,6 +55,14 @@ def pytest_runtest_setup(item):
     if "required_hardware" in attrmarker.kwargs:
         if attrmarker.kwargs["required_hardware"] != g_marvin_filter["required_hardware"]:
             pytest.skip("doesnt match hardware")
+    elif "hypervisor_in" in attrmarker.kwargs:
+        found = False
+        for t in attrmarker.kwargs["hypervisor_in"]:
+            if t in g_marvin_filter["hypervisors"]:
+                found = True
+                break
+        if found is False:
+            pytest.skip("hypervisor doesn't match:" + str(attrmarker.kwargs["hypervisor_in"]))
     elif "tags" in attrmarker.kwargs:
         found = False
         for t in attrmarker.kwargs["tags"]:
@@ -80,8 +75,6 @@ def pytest_runtest_setup(item):
 @pytest.fixture(scope="session", autouse=True)
 def marvin_init_session():
     result = getMarvin()
-    logger = result.getLogger()
-    logger.debug("in session")
     if result is None:
         pytest.fail("failed to init marvin plugin")
 
@@ -99,8 +92,6 @@ def marvin_init_function(request):
     if request.cls is not None:
         return
     marvinObj = getMarvin()
-    logger = marvinObj.getLogger()
-    #logger.debug("in function")
 
     setattr(request.node, "testClient", marvinObj.getTestClient())
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d002c52a/tools/marvin/marvin/utils.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/utils.py b/tools/marvin/marvin/utils.py
index fd40a8b..e9ad1d1 100644
--- a/tools/marvin/marvin/utils.py
+++ b/tools/marvin/marvin/utils.py
@@ -9,7 +9,7 @@ def getMarvin():
     deployDc = os.environ.get("MARVIN_DEPLOY_DC", "false")
     if deployDc in ["True", "true"]:
         deployDcb = True
-    zoneName = os.environ.get("MARVIN_ZONE_NAME", "Sandbox-simulator")
+    zoneName = getCurrentZoneName()
     hypervisor_type = os.environ.get("MARVIN_HYPERVISOR_TYPE", "simulator")
     logFolder = os.environ.get("MARVIN_LOG_FOLDER", os.path.expanduser(os.path.join("~","marvin")))
 
@@ -26,6 +26,12 @@ def getMarvin():
     else:
         return marvinObj
 
+def getCurrentZoneName():
+    return os.environ.get("MARVIN_ZONE_NAME", "Sandbox-simulator")
+
+def getHypervisorType():
+    return os.environ.get("MARVIN_HYPERVISOR_TYPE", "simulator")
+
 def initTestClass(cls, idenifier):
     marvinObj = None
     if hasattr(cls, "marvinObj"):


Mime
View raw message