Skip to content

Commit

Permalink
The rack and dc are copied from parent
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon Pyżalski committed Oct 8, 2014
1 parent 5396a1a commit f120ae9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/ralph/deployment/fixtures/vm_creation_setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
fields:
name: Test rack
model: 1
dc: Test DC

-
model: discovery.device
Expand All @@ -107,6 +108,8 @@
name: Test device
parent: 1
model: 2
rack: Test rack
dc: Test DC

-
model: discovery.device
Expand All @@ -122,6 +125,7 @@
name: Test device with wrong rack
model: 2
parent: 4
rack: Wrong rack


-
Expand Down
21 changes: 21 additions & 0 deletions src/ralph/deployment/tests/functional/tests_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import json

from ralph.account.models import BoundPerm, Profile, Perm
from ralph.discovery.models_device import Device
from ralph.business.models import DataCenter
from django.core.cache import cache
from django.test import TestCase
from ralph.ui.tests.global_utils import create_user, UserTestCase
Expand Down Expand Up @@ -68,6 +70,7 @@ class TestVMCreation(UserTestCase):

def test_correct(self):
"""Correctly setup the new VM"""
rack = Device.objects.get(pk=1)
response = self.post(
'/api/add_vm', json.dumps({
'mac':'82:3c:cf:94:9d:f2',
Expand All @@ -79,6 +82,24 @@ def test_correct(self):
content_type='application/json'
)
self.assertEqual(response.status_code, 201)
new_vm_data = json.loads(self.get(response['Location']).content)
self.assertEqual(new_vm_data['rack'], rack.name)
self.assertEqual(new_vm_data['dc'], rack.dc)


def test_correct_null_role(self):
"""Correctly setup the new VM, no role provided"""
response = self.post(
'/api/add_vm', json.dumps({
'mac':'82:3c:cf:94:9d:f2',
'management-ip':'10.1.1.2',
'network':'test_network',
'venture':'test_venture',
'venture-role': None,
}),
content_type='application/json'
)
self.assertEqual(response.status_code, 201)

def test_missing_data(self):
"""Missing venture_role."""
Expand Down
5 changes: 4 additions & 1 deletion src/ralph/ui/views/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ def post(self, request, *args, **kwargs):
Venture,
symbol=data['venture']
)
role = get_object_or_404(
role_name = data.get('venture-role')
role = role_name and get_object_or_404(
VentureRole,
venture=venture,
name=data['venture-role']
Expand All @@ -487,6 +488,8 @@ def post(self, request, *args, **kwargs):
device.parent = parent
device.venture = venture
device.venture_role = role
device.rack = parent.rack
device.dc = parent.dc
device.save()
IPAddress.objects.create(
address=ip_addr,
Expand Down

0 comments on commit f120ae9

Please sign in to comment.