Beispiel #1
0
 def test_update_interface_updates_non_admin(self):
     user = factory.make_User()
     node = factory.make_Node(owner=user,
                              interface=False,
                              node_type=NODE_TYPE.DEVICE)
     handler = DeviceHandler(user, {}, None)
     name = factory.make_name("eth")
     mac_address = factory.make_mac_address()
     ip_assignment = DEVICE_IP_ASSIGNMENT_TYPE.DYNAMIC
     params = {
         "system_id": node.system_id,
         "name": name,
         "mac_address": mac_address,
         "ip_assignment": ip_assignment,
     }
     handler.create_interface(params)
     interface = node.interface_set.first()
     self.assertIsNotNone(interface)
     new_mac_address = factory.make_mac_address()
     new_params = {
         "system_id": node.system_id,
         "interface_id": interface.id,
         "name": name,
         "mac_address": new_mac_address,
         "ip_assignment": ip_assignment,
     }
     handler.update_interface(new_params)
     data = self.dehydrate_device(node, user)["interfaces"]
     self.assertEqual(1, len(data))
     self.assertEqual(data[0]["mac_address"], new_mac_address)
Beispiel #2
0
 def test_update_interface_updates(self):
     user = factory.make_admin()
     node = factory.make_Node(interface=False, node_type=NODE_TYPE.DEVICE)
     handler = DeviceHandler(user, {})
     name = factory.make_name("eth")
     mac_address = factory.make_mac_address()
     ip_assignment = factory.pick_enum(DEVICE_IP_ASSIGNMENT_TYPE)
     params = {
         "system_id": node.system_id,
         "name": name,
         "mac_address": mac_address,
         "ip_assignment": ip_assignment,
         }
     if ip_assignment == DEVICE_IP_ASSIGNMENT_TYPE.STATIC:
         subnet = factory.make_Subnet()
         params['subnet'] = subnet.id
         ip_address = str(IPAddress(IPNetwork(subnet.cidr).first))
         params['ip_address'] = ip_address
     elif ip_assignment == DEVICE_IP_ASSIGNMENT_TYPE.EXTERNAL:
         ip_address = factory.make_ip_address()
         params['ip_address'] = ip_address
     handler.create_interface(params)
     interface = node.interface_set.first()
     self.assertIsNotNone(interface)
     new_name = factory.make_name("eth")
     new_ip_assignment = factory.pick_enum(DEVICE_IP_ASSIGNMENT_TYPE)
     new_params = {
         "system_id": node.system_id,
         "interface_id": interface.id,
         "name": new_name,
         "mac_address": mac_address,
         "ip_assignment": new_ip_assignment,
     }
     if new_ip_assignment == DEVICE_IP_ASSIGNMENT_TYPE.STATIC:
         new_subnet = factory.make_Subnet()
         new_params['subnet'] = new_subnet.id
         new_ip_address = str(IPAddress(IPNetwork(new_subnet.cidr).first))
         new_params['ip_address'] = new_ip_address
     elif new_ip_assignment == DEVICE_IP_ASSIGNMENT_TYPE.EXTERNAL:
         new_ip_address = factory.make_ip_address()
         new_params['ip_address'] = new_ip_address
     handler.update_interface(new_params)
     data = self.dehydrate_device(node, user)['interfaces']
     self.assertEqual(1, len(data))
     self.assertEqual(data[0]['ip_assignment'], new_ip_assignment)
     if new_ip_assignment != DEVICE_IP_ASSIGNMENT_TYPE.DYNAMIC:
         self.assertEqual(data[0]['ip_address'], new_ip_address)