From ffe0d7062455b1928423ca772b2a63a77b1bdb91 Mon Sep 17 00:00:00 2001 From: Mark Hamilton Date: Sun, 29 Jul 2018 16:19:49 -0700 Subject: [PATCH] switched from HV to host. Host is more general --- examples/conftest.py | 4 +- testpool/core/algo.py | 6 +- testpool/core/profile.py | 6 +- testpool/core/resource.py | 16 ++--- testpool/core/server.py | 40 +++++------ testpool/db/testpool_fake/api.py | 2 +- testpool/db/testpool_profile/views.py | 2 +- testpool/db/testpooldb/admin.py | 6 +- .../migrations/0003_auto_20180729_2300.py | 19 ++++++ .../migrations/0004_auto_20180729_2317.py | 20 ++++++ testpool/db/testpooldb/models.py | 6 +- testpool/db/testpooldb/tests.py | 24 +++---- testpool/libexec/docker/api.py | 2 +- testpool/libexec/docker/testsuite.py | 68 ++++++++++--------- testpool/libexec/fake/api.py | 2 +- testpool/libexec/fake/testsuite.py | 31 +++++---- testpool/libexec/kvm/api.py | 2 +- testpool/libexec/kvm/testsuite.py | 55 +++++++-------- 18 files changed, 177 insertions(+), 134 deletions(-) create mode 100644 testpool/db/testpooldb/migrations/0003_auto_20180729_2300.py create mode 100644 testpool/db/testpooldb/migrations/0004_auto_20180729_2317.py diff --git a/examples/conftest.py b/examples/conftest.py index 89db4cf..8a8e2f1 100644 --- a/examples/conftest.py +++ b/examples/conftest.py @@ -55,11 +55,11 @@ def teardown_db(): # assert testpool.core.commands.args_process(None, args) == 0 profiles = testpool.core.profile.profile_list() for profile in profiles: - if profile.hv.product != "fake": + if profile.host.product != "fake": continue if profile.name != GLOBAL["profile"]: continue - if profile.hv.connection != GLOBAL["connection"]: + if profile.host.connection != GLOBAL["connection"]: continue testpool.core.profile.profile_remove(GLOBAL["profile"], True) diff --git a/testpool/core/algo.py b/testpool/core/algo.py index e980315..0eea1b4 100644 --- a/testpool/core/algo.py +++ b/testpool/core/algo.py @@ -238,11 +238,11 @@ def profile_add(connection, product, profile, resource_max, template): """ Add a profile. """ logging.debug("profile_add %s %s", profile, template) - (hv1, _) = models.HV.objects.get_or_create(connection=connection, - product=product) + (host1, _) = models.Host.objects.get_or_create(connection=connection, + product=product) defaults = {"resource_max": resource_max, "template_name": template} (profile1, _) = models.Profile.objects.update_or_create(name=profile, - hv=hv1, + host=host1, defaults=defaults) ## # Check to see if the number of Resources should change. diff --git a/testpool/core/profile.py b/testpool/core/profile.py index 2eb2c71..c049ded 100644 --- a/testpool/core/profile.py +++ b/testpool/core/profile.py @@ -84,7 +84,7 @@ def _do_profile_detail(args): ## # Check to see if the number of Resources should change. exts = testpool.core.ext.api_ext_list() - pool = exts[profile.hv.product].pool_get(profile) + pool = exts[profile.host.product].pool_get(profile) info = pool.info_get() print "Model: " + str(info.model) @@ -109,8 +109,8 @@ def _do_profile_list(_): "Status") for profile in models.Profile.objects.all(): current = profile.resource_available() - print fmt % (profile.name, profile.hv.product, profile.hv.connection, - profile.template_name, + print fmt % (profile.name, profile.host.product, + profile.host.connection, profile.template_name, "%s/%s" % (current, profile.resource_max), profile.status_str()) return 0 diff --git a/testpool/core/resource.py b/testpool/core/resource.py index df4ea89..f30f7a4 100644 --- a/testpool/core/resource.py +++ b/testpool/core/resource.py @@ -30,8 +30,8 @@ def _profile_get(connection, product, profile): """ Return the profile given the parameters. """ - hv1 = models.HV.objects.get(connection=connection, product=product) - return models.Profile.objects.get(name=profile, hv=hv1) + host1 = models.Host.objects.get(connection=connection, product=product) + return models.Profile.objects.get(name=profile, host=host1) def _do_resource_incr(args): @@ -74,7 +74,7 @@ def _do_resource_detail(args): name=args.name) exts = ext.api_ext_list() - pool = exts[rsrc.profile.hv.product].pool_get(rsrc.profile) + pool = exts[rsrc.profile.host.product].pool_get(rsrc.profile) print "Name: %s" % args.name ip_address = pool.ip_get(args.name) @@ -105,16 +105,16 @@ def _do_resource_contain(args): for pattern in args.patterns: rsrcs = rsrcs.filter( Q(name__contains=pattern) | - Q(profile__hv__connection__contains=pattern) | - Q(profile__hv__product__contains=pattern) | + Q(profile__host__connection__contains=pattern) | + Q(profile__host__product__contains=pattern) | Q(profile__name__contains=pattern)).order_by("name") print fmt % ("Profile", "Connection", "Name", "Status", "IP", "Reserved Time") for rsrc in rsrcs: - print fmt % (rsrc.profile.name, rsrc.profile.hv.connection, rsrc.name, - models.Resource.status_to_str(rsrc.status), rsrc.ip_addr, - rsrc.action_time) + print fmt % (rsrc.profile.name, rsrc.profile.host.connection, + rsrc.name, models.Resource.status_to_str(rsrc.status), + rsrc.ip_addr, rsrc.action_time) return 0 diff --git a/testpool/core/server.py b/testpool/core/server.py index 0f8b099..6ad510b 100644 --- a/testpool/core/server.py +++ b/testpool/core/server.py @@ -148,7 +148,7 @@ def adapt(exts): PROFILE_LOGGER.info(profile=profile1.name, resource_count=profile1.resource_available(), resource_max=profile1.resource_max) - ext1 = exts[profile1.hv.product] + ext1 = exts[profile1.host.product] pool = ext1.pool_get(profile1) algo.adapt(pool, profile1) @@ -161,9 +161,9 @@ def action_destroy(exts, rsrc): try: rsrc_name = rsrc.name LOGGER.info("%s: action_destroy started %s %s", - rsrc.profile.name, rsrc.profile.hv.product, rsrc.name) + rsrc.profile.name, rsrc.profile.host.product, rsrc.name) - ext1 = exts[rsrc.profile.hv.product] + ext1 = exts[rsrc.profile.host.product] pool = ext1.pool_get(rsrc.profile) profile1 = rsrc.profile @@ -193,9 +193,9 @@ def action_clone(exts, rsrc): try: rsrc_name = rsrc.name LOGGER.info("%s: action_clone started %s %s", - rsrc.profile.name, rsrc.profile.hv.product, rsrc.name) + rsrc.profile.name, rsrc.profile.host.product, rsrc.name) - ext1 = exts[rsrc.profile.hv.product] + ext1 = exts[rsrc.profile.host.product] pool = ext1.pool_get(rsrc.profile) profile1 = rsrc.profile @@ -253,7 +253,7 @@ def setup(exts): profile1.template_name, rsrcs.count(), profile1.resource_max) - ext1 = exts[profile1.hv.product] + ext1 = exts[profile1.host.product] pool = ext1.pool_get(profile1) ## @@ -306,11 +306,11 @@ def action_attr(exts, rsrc): """ Retrieve attributes. """ LOGGER.info("%s: action_attr started %s %s", - rsrc.profile.name, rsrc.profile.hv.product, rsrc.name) + rsrc.profile.name, rsrc.profile.host.product, rsrc.name) ## # If resource expires reclaim it. - ext1 = exts[rsrc.profile.hv.product] + ext1 = exts[rsrc.profile.host.product] pool = ext1.pool_get(rsrc.profile) rsrc.ip_addr = pool.ip_get(rsrc.name) if rsrc.ip_addr: @@ -466,12 +466,12 @@ def fake_args(): def test_setup(self): """ test_setup. """ - (hv1, _) = models.HV.objects.get_or_create(connection="localhost", - product="fake") + (host1, _) = models.Host.objects.get_or_create(connection="localhost", + product="fake") defaults = {"resource_max": 1, "template_name": "test.template"} (profile1, _) = models.Profile.objects.update_or_create( - name=self.profile_name, hv=hv1, defaults=defaults) + name=self.profile_name, host=host1, defaults=defaults) self.assertTrue(profile1) args = ModelTestCase.fake_args() @@ -493,11 +493,11 @@ def test_shrink(self): product = "fake" connection = "localhost" - (hv1, _) = models.HV.objects.get_or_create(connection=connection, - product=product) + (host1, _) = models.Host.objects.get_or_create(connection=connection, + product=product) defaults = {"resource_max": 10, "template_name": "test.template"} (profile1, _) = models.Profile.objects.update_or_create( - name=self.profile_name, hv=hv1, defaults=defaults) + name=self.profile_name, host=host1, defaults=defaults) ## # Now shrink the pool to two @@ -518,11 +518,11 @@ def test_expand(self): product = "fake" connection = "localhost" - (hv1, _) = models.HV.objects.get_or_create(connection=connection, - product=product) + (host1, _) = models.Host.objects.get_or_create(connection=connection, + product=product) defaults = {"resource_max": 3, "template_name": "fake.template"} (profile1, _) = models.Profile.objects.update_or_create( - name=self.profile_name, hv=hv1, defaults=defaults) + name=self.profile_name, host=host1, defaults=defaults) ## # Now expand to 12 @@ -546,14 +546,14 @@ def test_expiration(self): ## # Create three resources. - (hv1, _) = models.HV.objects.get_or_create(connection=connection, - product=product) + (host1, _) = models.Host.objects.get_or_create(connection=connection, + product=product) defaults = { "resource_max": resource_max, "template_name": "test.template" } (profile1, _) = models.Profile.objects.update_or_create( - name=self.profile_name, hv=hv1, defaults=defaults) + name=self.profile_name, host=host1, defaults=defaults) args = ModelTestCase.fake_args() # Run the main so that the state-machine runs to build the three diff --git a/testpool/db/testpool_fake/api.py b/testpool/db/testpool_fake/api.py index 3f93333..1bcf345 100644 --- a/testpool/db/testpool_fake/api.py +++ b/testpool/db/testpool_fake/api.py @@ -25,7 +25,7 @@ from django.views.decorators.csrf import csrf_exempt from django.http import Http404 from django.core.exceptions import PermissionDenied -from testpooldb.models import HV +from testpooldb.models import Host from testpooldb.models import Profile from testpooldb.models import Resource from testpool_profile.views import ProfileStats diff --git a/testpool/db/testpool_profile/views.py b/testpool/db/testpool_profile/views.py index 6765e30..9dbc2be 100644 --- a/testpool/db/testpool_profile/views.py +++ b/testpool/db/testpool_profile/views.py @@ -38,7 +38,7 @@ def __init__(self, profile): # The ID is needed for the JSON view. self.id = profile.id # - self.connection = profile.hv.connection + self.connection = profile.host.connection self.name = profile.name self.resource_max = profile.resource_max self.vm_ready = 0 diff --git a/testpool/db/testpooldb/admin.py b/testpool/db/testpooldb/admin.py index 783e980..5419ffa 100644 --- a/testpool/db/testpooldb/admin.py +++ b/testpool/db/testpooldb/admin.py @@ -49,14 +49,14 @@ class ProfileAdmin(admin.ModelAdmin): model = models.Profile -class HVAdmin(admin.ModelAdmin): +class HostAdmin(admin.ModelAdmin): """ Administrate testplan content. """ - model = models.HV + model = models.Host admin.site.register(models.Key, KeyAdmin) admin.site.register(models.KVP, KVPAdmin) admin.site.register(models.Resource, ResourceAdmin) admin.site.register(models.Profile, ProfileAdmin) -admin.site.register(models.HV, HVAdmin) +admin.site.register(models.Host, HostAdmin) diff --git a/testpool/db/testpooldb/migrations/0003_auto_20180729_2300.py b/testpool/db/testpooldb/migrations/0003_auto_20180729_2300.py new file mode 100644 index 0000000..cc7a357 --- /dev/null +++ b/testpool/db/testpooldb/migrations/0003_auto_20180729_2300.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.13 on 2018-07-29 23:00 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('testpooldb', '0002_auto_20180429_1917'), + ] + + operations = [ + migrations.RenameModel( + old_name='HV', + new_name='Host', + ), + ] diff --git a/testpool/db/testpooldb/migrations/0004_auto_20180729_2317.py b/testpool/db/testpooldb/migrations/0004_auto_20180729_2317.py new file mode 100644 index 0000000..ed138ee --- /dev/null +++ b/testpool/db/testpooldb/migrations/0004_auto_20180729_2317.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.13 on 2018-07-29 23:17 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('testpooldb', '0003_auto_20180729_2300'), + ] + + operations = [ + migrations.RenameField( + model_name='profile', + old_name='hv', + new_name='host', + ), + ] diff --git a/testpool/db/testpooldb/models.py b/testpool/db/testpooldb/models.py index ee17515..281697c 100644 --- a/testpool/db/testpooldb/models.py +++ b/testpool/db/testpooldb/models.py @@ -229,7 +229,7 @@ def __str__(self): return "%s %s" % (str(self.profile), str(self.kvp)) -class HV(models.Model): +class Host(models.Model): """ Hypervisor. """ connection = models.CharField(max_length=128) @@ -257,7 +257,7 @@ class Profile(models.Model): BAD = 0 name = models.CharField(max_length=128, unique=True) - hv = models.ForeignKey(HV, on_delete=models.CASCADE) + host = models.ForeignKey(Host, on_delete=models.CASCADE) template_name = models.CharField(max_length=128) kvps = models.ManyToManyField(KVP, through="ProfileKVP") resource_max = models.IntegerField(default=1) @@ -300,7 +300,7 @@ def __contains__(self, srch): if srch in str(self.name): return True - if self.hv.__contains__(srch): + if self.host.__contains__(srch): return True if srch in str(self.template_name): return True diff --git a/testpool/db/testpooldb/tests.py b/testpool/db/testpooldb/tests.py index df8693a..0bf5762 100644 --- a/testpool/db/testpooldb/tests.py +++ b/testpool/db/testpooldb/tests.py @@ -23,7 +23,7 @@ from .models import Profile from .models import Key from .models import KVP -from .models import HV +from .models import Host from .models import Resource from .models import ResourceKVP @@ -39,9 +39,9 @@ def test_profile(self): kvps = (KVP.objects.create(key=key1, value="value1"), KVP.objects.create(key=key2, value="value2")) - hv1 = HV.objects.create(connection="localhost") + host1 = Host.objects.create(connection="localhost") - profile1 = Profile.objects.create(name="profile1", hv=hv1, + profile1 = Profile.objects.create(name="profile1", host=host1, resource_max=3, template_name="template.ubuntu1404") for kvp in kvps: @@ -53,10 +53,10 @@ def test_profile(self): def test_vm(self): """ Generate several resource instances. """ - hv1 = HV.objects.create(connection="localhost") - self.assertTrue(hv1) + host1 = Host.objects.create(connection="localhost") + self.assertTrue(host1) - profile1 = Profile.objects.create(name="profile1", hv=hv1, + profile1 = Profile.objects.create(name="profile1", host=host1, resource_max=3, template_name="template.ubuntu1404", expiration=10*60*60*10000000) @@ -71,10 +71,10 @@ def test_vm(self): def test_vm_attr(self): """ Test adding attribute to a resource. """ - hv1 = HV.objects.create(connection="localhost") - self.assertTrue(hv1) + host1 = Host.objects.create(connection="localhost") + self.assertTrue(host1) - profile1 = Profile.objects.create(name="profile1", hv=hv1, + profile1 = Profile.objects.create(name="profile1", host=host1, resource_max=3, template_name="template.ubuntu1404", expiration=10*60*60*10000000) @@ -90,9 +90,9 @@ def test_vm_attr(self): def test_exception(self): """ Test storing an exception in a profile. """ - hv1 = HV.objects.create(connection="localhost") - self.assertTrue(hv1) - profile1 = Profile.objects.create(name="profile1", hv=hv1, + host1 = Host.objects.create(connection="localhost") + self.assertTrue(host1) + profile1 = Profile.objects.create(name="profile1", host=host1, resource_max=3, template_name="template.ubuntu1404", expiration=10*60*60) diff --git a/testpool/libexec/docker/api.py b/testpool/libexec/docker/api.py index cbc6f96..51cbccc 100755 --- a/testpool/libexec/docker/api.py +++ b/testpool/libexec/docker/api.py @@ -166,7 +166,7 @@ def info_get(self): def pool_get(profile): """ Return a handle to the KVM API. """ try: - return Pool(profile.hv.connection, profile.name) + return Pool(profile.host.connection, profile.name) except libvirt.libvirtError, arg: # LOGGER.exception(arg) raise exceptions.ProfileError(str(arg), profile) diff --git a/testpool/libexec/docker/testsuite.py b/testpool/libexec/docker/testsuite.py index a6a8de2..9540a1b 100644 --- a/testpool/libexec/docker/testsuite.py +++ b/testpool/libexec/docker/testsuite.py @@ -48,10 +48,10 @@ class Testsuite(unittest.TestCase): def setUp(self): """ Create docker profile. """ - (hv1, _) = models.HV.objects.get_or_create( + (host1, _) = models.Host.objects.get_or_create( connection=CONNECTION, product=PRODUCT) defaults = {"resource_max": 3, "template_name": TEMPLATE} - models.Profile.objects.update_or_create(name=TEST_PROFILE, hv=hv1, + models.Profile.objects.update_or_create(name=TEST_PROFILE, host=host1, defaults=defaults) pool = api.Pool(CONNECTION, "test") @@ -73,9 +73,10 @@ def tearDown(self): pass try: - hv1 = models.HV.objects.get(connection=CONNECTION, product=PRODUCT) - hv1.delete() - except models.HV.DoesNotExist: + host1 = models.Host.objects.get(connection=CONNECTION, + product=PRODUCT) + host1.delete() + except models.Host.DoesNotExist: pass def test_clone(self): @@ -83,8 +84,8 @@ def test_clone(self): count = 3 - hv1 = docker.from_env() - self.assertTrue(hv1) + host1 = docker.from_env() + self.assertTrue(host1) pool = api.Pool(CONNECTION, "test") self.assertIsNotNone(pool) @@ -109,11 +110,11 @@ def test_destroy_missing(self): profile1 = models.Profile.objects.get(name=TEST_PROFILE) - hv1 = api.pool_get(profile1) - self.assertTrue(hv1) + host1 = api.pool_get(profile1) + self.assertTrue(host1) name = "%s.destroy" % TEMPLATE - hv1.destroy(name) + host1.destroy(name) # pylint: disable=R0903 @@ -136,29 +137,30 @@ def tearDown(self): """ Make sure profile is removed. """ try: - hv1 = models.HV.objects.get(connection=CONNECTION, - product=PRODUCT) - profile1 = models.Profile.objects.get(name=TEST_PROFILE, hv=hv1) + host1 = models.Host.objects.get(connection=CONNECTION, + product=PRODUCT) + profile1 = models.Profile.objects.get(name=TEST_PROFILE, + host=host1) pool = api.pool_get(profile1) algo.destroy(pool, profile1) profile1.delete() - except models.HV.DoesNotExist: + except models.Host.DoesNotExist: pass except models.Profile.DoesNotExist: pass - hv1 = docker.from_env() + host1 = docker.from_env() pool = api.Pool(CONNECTION, "test") def test_setup(self): """ test_setup. """ - (hv1, _) = models.HV.objects.get_or_create(connection=CONNECTION, - product=PRODUCT) + (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION, + product=PRODUCT) defaults = {"resource_max": 1, "template_name": TEMPLATE} (profile1, _) = models.Profile.objects.update_or_create( - name=TEST_PROFILE, hv=hv1, defaults=defaults) + name=TEST_PROFILE, host=host1, defaults=defaults) args = FakeArgs() server.args_process(args) @@ -168,10 +170,10 @@ def test_setup(self): def test_create_one(self): """ Create one container. """ - (hv1, _) = models.HV.objects.get_or_create(connection=CONNECTION, - product=PRODUCT) + (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION, + product=PRODUCT) defaults = {"resource_max": 1, "template_name": TEMPLATE} - models.Profile.objects.update_or_create(name=TEST_PROFILE, hv=hv1, + models.Profile.objects.update_or_create(name=TEST_PROFILE, host=host1, defaults=defaults) args = FakeArgs() @@ -181,10 +183,10 @@ def test_create_one(self): def test_create_two(self): """ Create one container. """ - (hv1, _) = models.HV.objects.get_or_create(connection=CONNECTION, - product=PRODUCT) + (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION, + product=PRODUCT) defaults = {"resource_max": 2, "template_name": TEMPLATE} - models.Profile.objects.update_or_create(name=TEST_PROFILE, hv=hv1, + models.Profile.objects.update_or_create(name=TEST_PROFILE, host=host1, defaults=defaults) args = FakeArgs() @@ -194,11 +196,11 @@ def test_create_two(self): def test_shrink(self): """ test_shrink. test when the profile shrinks. """ - (hv1, _) = models.HV.objects.get_or_create(connection=CONNECTION, - product=PRODUCT) + (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION, + product=PRODUCT) defaults = {"resource_max": 3, "template_name": TEMPLATE} (profile1, _) = models.Profile.objects.update_or_create( - name=TEST_PROFILE, hv=hv1, defaults=defaults) + name=TEST_PROFILE, host=host1, defaults=defaults) args = FakeArgs() server.args_process(args) @@ -222,11 +224,11 @@ def test_shrink(self): def test_expand(self): """ test_expand. Check when profile increases. """ - (hv1, _) = models.HV.objects.get_or_create(connection=CONNECTION, - product=PRODUCT) + (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION, + product=PRODUCT) defaults = {"resource_max": 2, "template_name": TEMPLATE} (profile1, _) = models.Profile.objects.update_or_create( - name=TEST_PROFILE, hv=hv1, defaults=defaults) + name=TEST_PROFILE, host=host1, defaults=defaults) ## # Now expand to 3 @@ -247,11 +249,11 @@ def test_expiration(self): resource_max = 3 - (hv1, _) = models.HV.objects.get_or_create(connection=CONNECTION, - product=PRODUCT) + (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION, + product=PRODUCT) defaults = {"resource_max": resource_max, "template_name": TEMPLATE} (profile1, _) = models.Profile.objects.update_or_create( - name=TEST_PROFILE, hv=hv1, defaults=defaults) + name=TEST_PROFILE, host=host1, defaults=defaults) args = FakeArgs() server.args_process(args) diff --git a/testpool/libexec/fake/api.py b/testpool/libexec/fake/api.py index 061628c..124284c 100755 --- a/testpool/libexec/fake/api.py +++ b/testpool/libexec/fake/api.py @@ -195,7 +195,7 @@ def info_get(self): def pool_get(profile1): """ Return a handle to the KVM API. """ - context = "%s/%s" % (profile1.hv.connection, profile1.name) + context = "%s/%s" % (profile1.host.connection, profile1.name) return Pool(context) diff --git a/testpool/libexec/fake/testsuite.py b/testpool/libexec/fake/testsuite.py index 64a0a2f..06c8314 100644 --- a/testpool/libexec/fake/testsuite.py +++ b/testpool/libexec/fake/testsuite.py @@ -26,10 +26,10 @@ class Testsuite(unittest.TestCase): def test_setup(self): """ test clone """ - (hv1, _) = models.HV.objects.get_or_create(connection="localhost", - product="fake") + (host1, _) = models.Host.objects.get_or_create(connection="localhost", + product="fake") (profile1, _) = models.Profile.objects.get_or_create( - name="fake.profile", hv=hv1, template_name="test.template", + name="fake.profile", host=host1, template_name="test.template", resource_max=10) pool = api.Pool("fake.profile") @@ -40,10 +40,10 @@ def test_setup(self): def test_pop(self): """ test_pop Popping resources. """ - (hv1, _) = models.HV.objects.get_or_create(connection="localhost", - product="fake") + (host1, _) = models.Host.objects.get_or_create(connection="localhost", + product="fake") (profile1, _) = models.Profile.objects.get_or_create( - name="fake.profile", hv=hv1, template_name="test.template", + name="fake.profile", host=host1, template_name="test.template", resource_max=10) pool = api.Pool("fake.profile") @@ -64,10 +64,10 @@ def test_push(self): profile_name = "fake.profile" - (hv1, _) = models.HV.objects.get_or_create(connection="localhost", - product="fake") + (host1, _) = models.Host.objects.get_or_create(connection="localhost", + product="fake") (profile1, _) = models.Profile.objects.get_or_create( - name="fake.profile", hv=hv1, resource_max=10, + name="fake.profile", host=host1, resource_max=10, template_name="test.template") pool = api.Pool("memory") @@ -89,10 +89,10 @@ def test_push_too_many(self): profile_name = "fake.profile" - (hv1, _) = models.HV.objects.get_or_create(connection="localhost", - product="fake") + (host1, _) = models.Host.objects.get_or_create(connection="localhost", + product="fake") (profile1, _) = models.Profile.objects.get_or_create( - name="fake.profile", hv=hv1, template_name="test.template", + name="fake.profile", host=host1, template_name="test.template", resource_max=10) pool = api.pool_get(profile1) @@ -123,9 +123,10 @@ def tearDown(self): pass try: - hv1 = models.HV.objects.get(connection="localhost", product="fake") - hv1.delete() - except models.HV.DoesNotExist: + host1 = models.Host.objects.get(connection="localhost", + product="fake") + host1.delete() + except models.Host.DoesNotExist: pass diff --git a/testpool/libexec/kvm/api.py b/testpool/libexec/kvm/api.py index cd5814e..a48bcb7 100755 --- a/testpool/libexec/kvm/api.py +++ b/testpool/libexec/kvm/api.py @@ -301,7 +301,7 @@ def pool_get(profile): # or # User qemu+tcp://username@hostname/system list --all try: - return Pool(profile.hv.connection, profile.name) + return Pool(profile.host.connection, profile.name) except libvirt.libvirtError, arg: # LOGGER.exception(arg) raise exceptions.ProfileError(str(arg), profile) diff --git a/testpool/libexec/kvm/testsuite.py b/testpool/libexec/kvm/testsuite.py index 6bb098b..4700d0e 100644 --- a/testpool/libexec/kvm/testsuite.py +++ b/testpool/libexec/kvm/testsuite.py @@ -48,10 +48,10 @@ class Testsuite(unittest.TestCase): def setUp(self): """ Create KVM profile. """ - (hv1, _) = models.HV.objects.get_or_create( + (host1, _) = models.Host.objects.get_or_create( connection=CONNECTION, product=PRODUCT) defaults = {"resource_max": 3, "template_name": TEMPLATE} - models.Profile.objects.update_or_create(name=TEST_PROFILE, hv=hv1, + models.Profile.objects.update_or_create(name=TEST_PROFILE, host=host1, defaults=defaults) def tearDown(self): @@ -66,10 +66,10 @@ def tearDown(self): pass try: - hv1 = models.HV.objects.get(connection=CONNECTION, - product=PRODUCT) - hv1.delete() - except models.HV.DoesNotExist: + host1 = models.Host.objects.get(connection=CONNECTION, + product=PRODUCT) + host1.delete() + except models.Host.DoesNotExist: pass def test_clone(self): @@ -78,8 +78,8 @@ def test_clone(self): Clone three resources. """ count = 2 - hv1 = libvirt.open(CONNECTION) - self.assertTrue(hv1) + host1 = libvirt.open(CONNECTION) + self.assertTrue(host1) pool = kvm.api.Pool(CONNECTION, "test") self.assertTrue(pool) @@ -131,15 +131,15 @@ def test_destroy_missing(self): profile1 = models.Profile.objects.get(name=TEST_PROFILE) - hv1 = kvm.api.pool_get(profile1) - self.assertTrue(hv1) + host1 = kvm.api.pool_get(profile1) + self.assertTrue(host1) hndl = libvirt.open(CONNECTION) self.assertTrue(hndl) try: name = "%s.destroy" % TEMPLATE - hv1.start(name) + host1.start(name) except libvirt.libvirtError: pass @@ -163,14 +163,15 @@ class TestsuiteServer(unittest.TestCase): def tearDown(self): """ Make sure profile is removed. """ try: - hv1 = models.HV.objects.get(connection=CONNECTION, - product=PRODUCT) - profile1 = models.Profile.objects.get(name=TEST_PROFILE, hv=hv1) + host1 = models.Host.objects.get(connection=CONNECTION, + product=PRODUCT) + profile1 = models.Profile.objects.get(name=TEST_PROFILE, + host=host1) pool = kvm.api.pool_get(profile1) algo.destroy(pool, profile1) profile1.delete() - except models.HV.DoesNotExist: + except models.Host.DoesNotExist: pass except models.Profile.DoesNotExist: pass @@ -178,12 +179,12 @@ def tearDown(self): def test_setup(self): """ test_setup. """ - (hv1, _) = models.HV.objects.get_or_create(connection=CONNECTION, - product=PRODUCT) + (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION, + product=PRODUCT) defaults = {"resource_max": 1, "template_name": TEMPLATE} (profile1, _) = models.Profile.objects.update_or_create( - name=TEST_PROFILE, hv=hv1, defaults=defaults) + name=TEST_PROFILE, host=host1, defaults=defaults) args = FakeArgs() server.args_process(args) @@ -194,11 +195,11 @@ def test_setup(self): def test_shrink(self): """ test_shrink. test when the profile shrinks. """ - (hv1, _) = models.HV.objects.get_or_create(connection=CONNECTION, - product=PRODUCT) + (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION, + product=PRODUCT) defaults = {"resource_max": 3, "template_name": TEMPLATE} (profile1, _) = models.Profile.objects.update_or_create( - name=TEST_PROFILE, hv=hv1, defaults=defaults) + name=TEST_PROFILE, host=host1, defaults=defaults) args = FakeArgs() server.args_process(args) @@ -224,11 +225,11 @@ def test_shrink(self): def test_expand(self): """ test_expand. Check when profile increases. """ - (hv1, _) = models.HV.objects.get_or_create(connection=CONNECTION, - product=PRODUCT) + (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION, + product=PRODUCT) defaults = {"resource_max": 2, "template_name": TEMPLATE} (profile1, _) = models.Profile.objects.update_or_create( - name=TEST_PROFILE, hv=hv1, defaults=defaults) + name=TEST_PROFILE, host=host1, defaults=defaults) ## # Now expand to 3 @@ -249,11 +250,11 @@ def test_expiration(self): resource_max = 3 - (hv1, _) = models.HV.objects.get_or_create(connection=CONNECTION, - product=PRODUCT) + (host1, _) = models.Host.objects.get_or_create(connection=CONNECTION, + product=PRODUCT) defaults = {"resource_max": resource_max, "template_name": TEMPLATE} (profile1, _) = models.Profile.objects.update_or_create( - name=TEST_PROFILE, hv=hv1, defaults=defaults) + name=TEST_PROFILE, host=host1, defaults=defaults) args = FakeArgs() server.args_process(args)