Commit 1d2f5fa0 by Czémán Arnold

request: decompose RequestTest which solves the "Segmentation fault" after test.…

request: decompose RequestTest which solves the "Segmentation fault" after test. fabfile: fix DataStore query. storage: small fixes for DataStore and Disk, add migration file. dashboard: fix test-vm-fixture
parent fa4cc272
......@@ -20,6 +20,10 @@
"pk": 1,
"model": "storage.datastore",
"fields": {
"hosts": [],
"type": "file",
"ceph_user": null,
"secret_uuid": null,
"path": "/disks",
"hostname": "wut",
"name": "diszkek"
......@@ -36,6 +40,7 @@
"destroyed": null,
"base": null,
"datastore": 1,
"bus": null,
"dev_num": "a",
"type": "qcow2-norm",
"size": 8589934592,
......
......@@ -37,7 +37,7 @@ except Exception as e:
else:
env.roledefs['node'] = [unicode(n.host.ipv4)
for n in _Node.objects.filter(enabled=True)]
env.roledefs['storage'] = [_DataStore.objects.get().hostname]
env.roledefs['storage'] = [_DataStore.get_default_datastore().hostname]
def update_all():
......
......@@ -30,7 +30,7 @@ from dashboard.tests.test_views import LoginMixin
from vm.operations import ResourcesOperation
class RequestTest(LoginMixin, MockCeleryMixin, TestCase):
class RequestTestBase(LoginMixin, MockCeleryMixin, TestCase):
fixtures = ['test-vm-fixture.json', 'node.json']
def setUp(self):
......@@ -57,10 +57,12 @@ class RequestTest(LoginMixin, MockCeleryMixin, TestCase):
tat.templates.add(InstanceTemplate.objects.get(pk=1))
def tearDown(self):
super(RequestTest, self).tearDown()
super(RequestTestBase, self).tearDown()
self.u1.delete()
self.us.delete()
class ResourceRequestTest(RequestTestBase):
def test_resources_request(self):
c = Client()
self.login(c, "user1")
......@@ -98,6 +100,8 @@ class RequestTest(LoginMixin, MockCeleryMixin, TestCase):
new_request = Request.objects.latest("pk")
self.assertEqual(new_request.status, "ACCEPTED")
class TemplateAccessRequestTest(RequestTestBase):
def test_template_access_request(self):
c = Client()
self.login(c, "user1")
......@@ -121,6 +125,8 @@ class RequestTest(LoginMixin, MockCeleryMixin, TestCase):
self.assertEqual(new_request.status, "ACCEPTED")
self.assertTrue(template.has_level(self.u1, "user"))
class LeaseRequestTest(RequestTestBase):
def test_lease_request(self):
c = Client()
self.login(c, "user1")
......
......@@ -16,18 +16,18 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('address', models.CharField(max_length=1024, verbose_name='address')),
('port', models.IntegerField(null=True, verbose_name='port')),
('port', models.IntegerField(null=True, verbose_name='port', blank=True)),
],
),
migrations.AddField(
model_name='datastore',
name='ceph_user',
field=models.CharField(max_length=255, null=True, verbose_name='Ceph username'),
field=models.CharField(max_length=255, null=True, verbose_name='Ceph username', blank=True),
),
migrations.AddField(
model_name='datastore',
name='secret_uuid',
field=models.CharField(max_length=255, null=True, verbose_name='uuid of secret'),
field=models.CharField(max_length=255, null=True, verbose_name='uuid of secret', blank=True),
),
migrations.AddField(
model_name='datastore',
......@@ -47,6 +47,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='datastore',
name='hosts',
field=models.ManyToManyField(to='storage.DataStoreHost', verbose_name='hosts'),
field=models.ManyToManyField(to='storage.DataStoreHost', verbose_name='hosts', blank=True),
),
]
......@@ -48,24 +48,25 @@ class DataStoreHost(Model):
""" Address and port of a data store.
"""
address = CharField(max_length=1024, verbose_name=_('address'))
port = IntegerField(null=True, verbose_name=_('port'))
port = IntegerField(null=True, blank=True, verbose_name=_('port'))
class DataStore(Model):
"""Collection of virtual disks.
"""
TYPES = [('file', 'filesystem'), ('ceph_block', 'Ceph block device')]
TYPES = (('file', 'filesystem'), ('ceph_block', 'Ceph block device'))
type = CharField(max_length=10, verbose_name=_('type'),
default='file', choices=TYPES)
name = CharField(max_length=100, unique=True, verbose_name=_('name'))
path = CharField(max_length=200, unique=True, verbose_name=_('path'))
hostname = CharField(max_length=40, verbose_name=_('hostname'))
hosts = ManyToManyField('DataStoreHost', verbose_name=_('hosts'))
ceph_user = CharField(max_length=255, null=True,
hosts = ManyToManyField('DataStoreHost', blank=True,
verbose_name=_('hosts'))
ceph_user = CharField(max_length=255, null=True, blank=True,
verbose_name=_('Ceph username'))
secret_uuid = CharField(max_length=255, null=True,
secret_uuid = CharField(max_length=255, null=True, blank=True,
verbose_name=_('uuid of secret'))
class Meta:
......@@ -95,20 +96,6 @@ class DataStore(Model):
self.disk_set.filter(
destroyed__isnull=False) if disk.is_deletable]
def get_disk_desc(self, disk):
if self.type == "ceph_block":
return disk.get_disk_desc_for_ceph_block_device()
return disk.get_disk_desc_for_filesystem()
def get_vmdisk_desc(self, disk):
if self.type == "ceph_block":
return disk.get_vmdisk_desc_for_ceph_block_device()
return disk.get_vmdisk_desc_for_filesystem()
def get_hosts(self):
return [(host.address, host.port) for host in self.hosts.all()]
......@@ -159,10 +146,10 @@ class Disk(TimeStampedModel):
"""A virtual disk.
"""
TYPES = [('qcow2-norm', 'qcow2 normal'), ('qcow2-snap', 'qcow2 snapshot'),
TYPES = (('qcow2-norm', 'qcow2 normal'), ('qcow2-snap', 'qcow2 snapshot'),
('ceph-norm', 'Ceph block normal'),
('ceph-snap', 'Ceph block snapshot'),
('iso', 'iso'), ('raw-ro', 'raw read-only'), ('raw-rw', 'raw')]
('iso', 'iso'), ('raw-ro', 'raw read-only'), ('raw-rw', 'raw'))
BUS_TYPES = (('virtio', 'virtio'), ('ide', 'ide'), ('scsi', 'scsi'))
name = CharField(blank=True, max_length=100, verbose_name=_("name"))
......@@ -379,12 +366,18 @@ class Disk(TimeStampedModel):
def get_vmdisk_desc(self):
"""Serialize disk object to the vmdriver.
"""
return self.datastore.get_vmdisk_desc(self)
if self.datastore.type == "ceph_block":
return self.get_vmdisk_desc_for_ceph_block_device()
return self.get_vmdisk_desc_for_filesystem()
def get_disk_desc(self):
"""Serialize disk object to the storage driver.
"""
return self.datastore.get_disk_desc(self)
if self.datastore.type == "ceph_block":
return self.get_disk_desc_for_ceph_block_device()
return self.get_disk_desc_for_filesystem()
def get_disk_desc_for_filesystem(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment