Skip to content

Commit

Permalink
switched from HV to host. Host is more general
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Hamilton committed Jul 29, 2018
1 parent a682bc1 commit ffe0d70
Show file tree
Hide file tree
Showing 18 changed files with 177 additions and 134 deletions.
4 changes: 2 additions & 2 deletions examples/conftest.py
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions testpool/core/algo.py
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions testpool/core/profile.py
Expand Up @@ -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)
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions testpool/core/resource.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
40 changes: 20 additions & 20 deletions testpool/core/server.py
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

##
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testpool/db/testpool_fake/api.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testpool/db/testpool_profile/views.py
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions testpool/db/testpooldb/admin.py
Expand Up @@ -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)
19 changes: 19 additions & 0 deletions 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',
),
]
20 changes: 20 additions & 0 deletions 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',
),
]
6 changes: 3 additions & 3 deletions testpool/db/testpooldb/models.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions testpool/db/testpooldb/tests.py
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion testpool/libexec/docker/api.py
Expand Up @@ -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)

0 comments on commit ffe0d70

Please sign in to comment.