diff options
author | Parker Berberian <pberberian@iol.unh.edu> | 2019-06-25 16:50:01 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2019-06-25 16:50:01 +0000 |
commit | d0ef55b1ba456858f811dd127986591c42312136 (patch) | |
tree | eace514ca2e30b2b5f9131560e0a357b094be879 /src/api | |
parent | d98ddb1cdf6d9dcd0ad79d12dd12d6c23a6ea2ba (diff) | |
parent | d33f2e3439825bb90e3b902018a3030f9f12f307 (diff) |
Merge "Adds Tests"
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/tests/test_models_unittest.py | 62 | ||||
-rw-r--r-- | src/api/urls.py | 4 |
2 files changed, 54 insertions, 12 deletions
diff --git a/src/api/tests/test_models_unittest.py b/src/api/tests/test_models_unittest.py index cabffc9..e6f97a6 100644 --- a/src/api/tests/test_models_unittest.py +++ b/src/api/tests/test_models_unittest.py @@ -15,6 +15,7 @@ from api.models import ( HostHardwareRelation, SoftwareRelation, AccessConfig, + SnapshotRelation ) from resource_inventory.models import ( @@ -103,8 +104,6 @@ class ValidBookingCreatesValidJob(TestCase): if not booking.resource: raise Exception("Booking does not have a resource when trying to pass to makeCompleteJob") - JobFactory.makeCompleteJob(booking) - return booking, compute_hostnames, "jump" def make_networks(self, hostprofile, nets): @@ -122,9 +121,12 @@ class ValidBookingCreatesValidJob(TestCase): return network_struct - # begin tests + ################################################################# + # Complete Job Tests + ################################################################# - def test_valid_access_configs(self): + def test_complete_job_makes_access_configs(self): + JobFactory.makeCompleteJob(self.booking) job = Job.objects.get(booking=self.booking) self.assertIsNotNone(job) @@ -142,7 +144,8 @@ class ValidBookingCreatesValidJob(TestCase): self.assertTrue(vpn_configs.filter(user=user).exists()) self.assertTrue(ssh_configs.filter(user=user).exists()) - def test_valid_network_configs(self): + def test_complete_job_makes_network_configs(self): + JobFactory.makeCompleteJob(self.booking) job = Job.objects.get(booking=self.booking) self.assertIsNotNone(job) @@ -180,7 +183,8 @@ class ValidBookingCreatesValidJob(TestCase): for host in netrelation_hosts: self.assertTrue(host in booking_hosts) - def test_valid_hardware_configs(self): + def test_complete_job_makes_hardware_configs(self): + JobFactory.makeCompleteJob(self.booking) job = Job.objects.get(booking=self.booking) self.assertIsNotNone(job) @@ -199,7 +203,8 @@ class ValidBookingCreatesValidJob(TestCase): host = relation.host self.assertEqual(config.hostname, host.template.resource.name) - def test_valid_software_configs(self): + def test_complete_job_makes_software_configs(self): + JobFactory.makeCompleteJob(self.booking) job = Job.objects.get(booking=self.booking) self.assertIsNotNone(job) @@ -218,10 +223,47 @@ class ValidBookingCreatesValidJob(TestCase): self.assertEqual(oconfig.scenario, self.booking.config_bundle.opnfv_config.first().scenario.name) for host in oconfig.roles.all(): - role_name = host.config.opnfvRole.name - if str(role_name) == "Jumphost": + role_name = host.config.host_opnfv_config.first().role.name + if str(role_name).lower() == "jumphost": self.assertEqual(host.template.resource.name, self.jump_hostname) - elif str(role_name) == "Compute": + elif str(role_name).lower() == "compute": self.assertTrue(host.template.resource.name in self.compute_hostnames) else: self.fail(msg="Host with non-configured role name related to job: " + str(role_name)) + + def test_make_snapshot_task(self): + host = self.booking.resource.hosts.first() + image = make_image(self.lab, -1, None, None, host.profile) + + Job.objects.create(booking=self.booking) + + JobFactory.makeSnapshotTask(image, self.booking, host) + + snap_relation = SnapshotRelation.objects.get(job=self.booking.job) + config = snap_relation.config + self.assertEqual(host.id, config.host.id) + self.assertEqual(config.dashboard_id, image.id) + self.assertEqual(snap_relation.snapshot.id, image.id) + + def test_make_hardware_configs(self): + hosts = self.booking.resource.hosts.all() + job = Job.objects.create(booking=self.booking) + JobFactory.makeHardwareConfigs(hosts=hosts, job=job) + + hardware_relations = HostHardwareRelation.objects.filter(job=job) + + self.assertEqual(hardware_relations.count(), hosts.count()) + + host_set = set([h.id for h in hosts]) + + for relation in hardware_relations: + try: + host_set.remove(relation.host.id) + except KeyError: + self.fail("Hardware Relation/Config not created for host " + str(relation.host)) + + self.assertEqual(relation.config.power, "on") + self.assertTrue(relation.config.ipmi_create) + # TODO: the rest of hwconf attrs + + self.assertEqual(len(host_set), 0) diff --git a/src/api/urls.py b/src/api/urls.py index d1f772a..7a48425 100644 --- a/src/api/urls.py +++ b/src/api/urls.py @@ -57,8 +57,8 @@ urlpatterns = [ path('labs/<slug:lab_name>/inventory', lab_inventory), path('labs/<slug:lab_name>/hosts/<slug:host_id>', lab_host), path('labs/<slug:lab_name>/hosts/<slug:host_id>/bmc', update_host_bmc), - path('labs/<slug:lab_name>/booking/<slug:booking_id>/pdf', get_pdf, name="get-pdf"), - path('labs/<slug:lab_name>/booking/<slug:booking_id>/idf', get_idf, name="get-idf"), + path('labs/<slug:lab_name>/booking/<int:booking_id>/pdf', get_pdf, name="get-pdf"), + path('labs/<slug:lab_name>/booking/<int:booking_id>/idf', get_idf, name="get-idf"), path('labs/<slug:lab_name>/jobs/<int:job_id>', specific_job), path('labs/<slug:lab_name>/jobs/<int:job_id>/<slug:task_id>', specific_task), path('labs/<slug:lab_name>/jobs/new', new_jobs), |