Merge "Mac addresses in nailgun should be represented as lowercase string"

This commit is contained in:
Jenkins 2013-11-27 13:56:51 +00:00 committed by Gerrit Code Review
commit 1fc5cfc4c4
5 changed files with 48 additions and 26 deletions

View File

@ -32,3 +32,11 @@ class JSON(types.TypeDecorator):
if value is not None: if value is not None:
value = json.loads(value) value = json.loads(value)
return value return value
class LowercaseString(types.TypeDecorator):
impl = types.String
def process_bind_param(self, value, dialect):
return value.lower()

View File

@ -26,6 +26,7 @@ from sqlalchemy.orm import relationship, backref
from nailgun.api.models.base import Base from nailgun.api.models.base import Base
from nailgun.api.models.fields import JSON from nailgun.api.models.fields import JSON
from nailgun.api.models.fields import LowercaseString
from nailgun.api.models.network import AllowedNetworks from nailgun.api.models.network import AllowedNetworks
from nailgun.api.models.network import NetworkAssignment from nailgun.api.models.network import NetworkAssignment
from nailgun.db import db from nailgun.db import db
@ -78,7 +79,7 @@ class Node(Base):
default='discover' default='discover'
) )
meta = Column(JSON, default={}) meta = Column(JSON, default={})
mac = Column(String(17), nullable=False, unique=True) mac = Column(LowercaseString(17), nullable=False, unique=True)
ip = Column(String(15)) ip = Column(String(15))
fqdn = Column(String(255)) fqdn = Column(String(255))
manufacturer = Column(Unicode(50)) manufacturer = Column(Unicode(50))
@ -244,7 +245,7 @@ class NodeNICInterface(Base):
ForeignKey('nodes.id', ondelete="CASCADE"), ForeignKey('nodes.id', ondelete="CASCADE"),
nullable=False) nullable=False)
name = Column(String(128), nullable=False) name = Column(String(128), nullable=False)
mac = Column(String(32), nullable=False) mac = Column(LowercaseString(17), nullable=False)
max_speed = Column(Integer) max_speed = Column(Integer)
current_speed = Column(Integer) current_speed = Column(Integer)
allowed_networks = relationship( allowed_networks = relationship(

View File

@ -9,7 +9,7 @@
"online": true, "online": true,
"pending_addition": false, "pending_addition": false,
"platform_name": "X9DRW", "platform_name": "X9DRW",
"mac": "00:25:90:6A:B1:10", "mac": "00:25:90:6a:b1:10",
"meta": { "meta": {
"cpu": { "cpu": {
"real": 2, "real": 2,
@ -115,13 +115,13 @@
}, },
"interfaces": [ "interfaces": [
{ {
"mac": "00:25:90:6A:B1:10", "mac": "00:25:90:6a:b1:10",
"max_speed": 1000, "max_speed": 1000,
"name": "eth0", "name": "eth0",
"current_speed": 1000 "current_speed": 1000
}, },
{ {
"mac": "00:25:90:6A:B1:11", "mac": "00:25:90:6a:b1:11",
"max_speed": 1000, "max_speed": 1000,
"name": "eth1", "name": "eth1",
"current_speed": null, "current_speed": null,
@ -283,7 +283,7 @@
"online": true, "online": true,
"pending_addition": false, "pending_addition": false,
"platform_name": "Inspiron N5110", "platform_name": "Inspiron N5110",
"mac": "58:91:CF:2A:C4:1B", "mac": "58:91:cF:2a:c4:1b",
"meta": { "meta": {
"memory": { "memory": {
"slots": 2, "slots": 2,
@ -305,20 +305,20 @@
"interfaces": [ "interfaces": [
{ {
"ip": "10.20.0.4", "ip": "10.20.0.4",
"mac": "58:91:CF:2A:C4:1B", "mac": "58:91:cF:2a:c4:1b",
"netmask": "255.255.255.0", "netmask": "255.255.255.0",
"current_speed": null, "current_speed": null,
"name": "wlan0" "name": "wlan0"
}, },
{ {
"ip": "192.168.70.234", "ip": "192.168.70.234",
"mac": "24:B6:FD:53:63:00", "mac": "24:b6:fd:53:63:00",
"max_speed": 100, "max_speed": 100,
"name": "eth0", "name": "eth0",
"current_speed": 10 "current_speed": 10
}, },
{ {
"mac": "54:78:EA:05:17:BA", "mac": "54:78:ea:05:17:ba",
"max_speed": 100, "max_speed": 100,
"name": "eth1", "name": "eth1",
"current_speed": 20 "current_speed": 20
@ -400,7 +400,7 @@
"online": true, "online": true,
"pending_addition": false, "pending_addition": false,
"platform_name": "X9SCD", "platform_name": "X9SCD",
"mac": "00:25:90:67:9F:B7", "mac": "00:25:90:67:9f:b7",
"meta": { "meta": {
"memory": { "memory": {
"slots": 4, "slots": 4,
@ -434,13 +434,13 @@
"name": "eth1", "name": "eth1",
"ip": "172.18.67.167", "ip": "172.18.67.167",
"netmask": "255.255.255.240", "netmask": "255.255.255.240",
"mac": "00:25:90:67:9F:B7", "mac": "00:25:90:67:9f:b7",
"max_speed": 1000, "max_speed": 1000,
"current_speed": 1000 "current_speed": 1000
}, },
{ {
"ip": "10.20.0.5", "ip": "10.20.0.5",
"mac": "00:25:90:67:9F:B6", "mac": "00:25:90:67:9f:b6",
"max_speed": 1000, "max_speed": 1000,
"name": "eth0", "name": "eth0",
"current_speed": null "current_speed": null
@ -524,7 +524,7 @@
"online": false, "online": false,
"pending_addition": false, "pending_addition": false,
"platform_name": "X9SCD", "platform_name": "X9SCD",
"mac": "00:25:90:67:9D:24", "mac": "00:25:90:67:9d:24",
"meta": { "meta": {
"memory": { "memory": {
"slots": 4, "slots": 4,
@ -555,7 +555,7 @@
}, },
"interfaces": [ "interfaces": [
{ {
"mac": "00:25:90:67:9D:25", "mac": "00:25:90:67:9d:25",
"max_speed": 1000, "max_speed": 1000,
"name": "eth1", "name": "eth1",
"current_speed": null "current_speed": null
@ -564,7 +564,7 @@
"name": "eth0", "name": "eth0",
"ip": "10.20.0.6", "ip": "10.20.0.6",
"netmask": "255.255.255.240", "netmask": "255.255.255.240",
"mac": "00:25:90:67:9D:24", "mac": "00:25:90:67:9d:24",
"max_speed": 1000, "max_speed": 1000,
"current_speed": 1000 "current_speed": 1000
} }
@ -648,7 +648,7 @@
"online": true, "online": true,
"pending_addition": false, "pending_addition": false,
"platform_name": "X9SCD", "platform_name": "X9SCD",
"mac": "00:25:90:67:9C:9C", "mac": "00:25:90:67:9c:9c",
"meta": { "meta": {
"memory": { "memory": {
"slots": 4, "slots": 4,
@ -679,7 +679,7 @@
}, },
"interfaces": [ "interfaces": [
{ {
"mac": "00:25:90:67:9C:9D", "mac": "00:25:90:67:9c:9d",
"max_speed": 1000, "max_speed": 1000,
"name": "eth1", "name": "eth1",
"current_speed": null, "current_speed": null,
@ -688,7 +688,7 @@
{ {
"name": "eth0", "name": "eth0",
"netmask": "255.255.255.224", "netmask": "255.255.255.224",
"mac": "00:25:90:67:9C:9C", "mac": "00:25:90:67:9c:9c",
"max_speed": 1000, "max_speed": 1000,
"current_speed": 1000 "current_speed": 1000
} }
@ -770,7 +770,7 @@
"ip": "10.20.0.63", "ip": "10.20.0.63",
"online": true, "online": true,
"pending_addition": false, "pending_addition": false,
"mac": "08:00:27:22:AB:AA", "mac": "08:00:27:22:ab:aa",
"meta": { "meta": {
"memory": { "memory": {
"total": 778887168 "total": 778887168
@ -780,7 +780,7 @@
"name": "eth0", "name": "eth0",
"ip": "10.20.0.63", "ip": "10.20.0.63",
"netmask": "255.255.255.0", "netmask": "255.255.255.0",
"mac": "08:00:27:22:AB:AA", "mac": "08:00:27:22:ab:aa",
"max_speed": 100, "max_speed": 100,
"current_speed": 100 "current_speed": 100
} }
@ -827,7 +827,7 @@
"ip": "10.20.0.226", "ip": "10.20.0.226",
"online": true, "online": true,
"pending_addition": false, "pending_addition": false,
"mac": "52:54:00:0E:B8:F5", "mac": "52:54:00:0e:b8:f5",
"meta": { "meta": {
"memory": { "memory": {
"slots": 1, "slots": 1,
@ -845,7 +845,7 @@
"name": "eth0", "name": "eth0",
"ip": "10.20.0.226", "ip": "10.20.0.226",
"netmask": "255.255.255.0", "netmask": "255.255.255.0",
"mac": "52:54:00:0E:B8:F5", "mac": "52:54:00:0e:b8:f5",
"max_speed": 100, "max_speed": 100,
"current_speed": 100 "current_speed": 100
} }
@ -891,7 +891,7 @@
"pending_addition": false, "pending_addition": false,
"fqdn": "slave-15.domain.tld", "fqdn": "slave-15.domain.tld",
"platform_name": "X9DRW", "platform_name": "X9DRW",
"mac": "00:25:90:6A:B1:84", "mac": "00:25:90:6a:b1:84",
"meta": { "meta": {
"cpu": { "cpu": {
"real": 2, "real": 2,
@ -1000,13 +1000,13 @@
"name": "p2p1", "name": "p2p1",
"ip": "172.18.67.170", "ip": "172.18.67.170",
"netmask": "255.255.255.240", "netmask": "255.255.255.240",
"mac": "00:25:90:6A:B1:84", "mac": "00:25:90:6a:b1:84",
"max_speed": 1000, "max_speed": 1000,
"current_speed": 1000 "current_speed": 1000
}, },
{ {
"ip": "10.20.0.7", "ip": "10.20.0.7",
"mac": "00:25:90:6A:B1:85", "mac": "00:25:90:6a:b1:b5",
"max_speed": 1000, "max_speed": 1000,
"name": "p2p2", "name": "p2p2",
"current_speed": null "current_speed": null

View File

@ -303,7 +303,7 @@ class Environment(object):
def _generate_random_mac(self): def _generate_random_mac(self):
mac = [randint(0x00, 0x7f) for _ in xrange(6)] mac = [randint(0x00, 0x7f) for _ in xrange(6)]
return ':'.join(map(lambda x: "%02x" % x, mac)).upper() return ':'.join(map(lambda x: "%02x" % x, mac)).lower()
def generate_interfaces_in_meta(self, amount): def generate_interfaces_in_meta(self, amount):
nics = [] nics = []

View File

@ -246,3 +246,16 @@ class TestHandlers(BaseIntegrationTest):
self.assertEquals(resp.status, 200) self.assertEquals(resp.status, 200)
response = json.loads(resp.body) response = json.loads(resp.body)
self.assertNotEquals(response[0]['id'], fake_id) self.assertNotEquals(response[0]['id'], fake_id)
def test_mac_address_should_be_in_lower_case(self):
meta = self.env.default_metadata()
new_mac = 'AA:BB:CC:DD:11:22'
self.env.set_interfaces_in_meta(meta, [
{'name': 'eth0', 'mac': new_mac}])
node = self.env.create_node(api=True, meta=meta)
resp = self.app.get(
reverse('NodeNICsHandler', kwargs={'node_id': node['id']}),
headers=self.default_headers)
self.assertEquals(resp.status, 200)
response = json.loads(resp.body)
self.assertNotEquals(response[0]['mac'], new_mac.lower())