Merge "Update schema definition for network interfaces port"

This commit is contained in:
Jenkins 2017-03-02 19:52:53 +00:00 committed by Gerrit Code Review
commit e89c1fb40f
3 changed files with 61 additions and 1 deletions

View File

@ -1325,7 +1325,7 @@ validators = {
"type": "string",
},
"port": {
"type": "string",
"type": "integer",
},
"duplex": {
"type": "string",

View File

@ -217,6 +217,9 @@ class TestCase(testtools.TestCase):
def assertNoContent(self, response):
self.assertEqual(requests.codes.NO_CONTENT, response.status_code)
def assertBadRequest(self, response):
self.assertEqual(requests.codes.BAD_REQUEST, response.status_code)
def get(self, url, headers=None, **params):
resp = self.session.get(
url, verify=False, headers=headers, params=params,

View File

@ -0,0 +1,57 @@
from craton.tests import functional
class APIv1NetworkInterfacesTest(functional.DeviceTestBase):
def setUp(self):
super(APIv1NetworkInterfacesTest, self).setUp()
self.interfaces_url = self.url + '/v1/network-interfaces'
def test_associate_network_device_with_a_host(self):
host = self.create_host('host-0', 'server', '127.0.0.1')
payload = {
'name': 'lo',
'ip_address': '127.0.0.1',
'device_id': host['id'],
'interface_type': 'loopback',
}
response = self.post(self.interfaces_url, data=payload)
self.assertSuccessCreated(response)
self.assertIn('Location', response.headers)
interface = response.json()
self.assertEqual(
'{}/{}'.format(self.interfaces_url, interface['id']),
response.headers['Location']
)
def test_port_must_be_an_integer_on_create(self):
host = self.create_host('host-0', 'server', '127.0.0.1')
payload = {
'name': 'lo',
'ip_address': '127.0.0.1',
'device_id': host['id'],
'interface_type': 'loopback',
'port': 'asdf',
}
response = self.post(self.interfaces_url, data=payload)
self.assertBadRequest(response)
def test_port_must_be_an_integer_on_update(self):
host = self.create_host('host-0', 'server', '127.0.0.1')
payload = {
'name': 'lo',
'ip_address': '127.0.0.1',
'device_id': host['id'],
'interface_type': 'loopback',
'port': 80,
}
response = self.post(self.interfaces_url, data=payload)
self.assertSuccessCreated(response)
interface = response.json()
url = self.interfaces_url + '/{}'.format(interface['id'])
payload = {'port': 'asdf'}
response = self.put(url, data=payload)
self.assertBadRequest(response)