Beispiel #1
0
 def test_link_subnet_calls_link_subnet_if_not_link_id(self):
     user = factory.make_admin()
     node = factory.make_Node(node_type=NODE_TYPE.DEVICE)
     handler = DeviceHandler(user, {})
     interface = factory.make_Interface(INTERFACE_TYPE.PHYSICAL, node=node)
     subnet = factory.make_Subnet()
     ip_assignment = factory.pick_enum(DEVICE_IP_ASSIGNMENT_TYPE)
     if ip_assignment == DEVICE_IP_ASSIGNMENT_TYPE.STATIC:
         mode = INTERFACE_LINK_TYPE.STATIC
     elif ip_assignment == DEVICE_IP_ASSIGNMENT_TYPE.DYNAMIC:
         mode = INTERFACE_LINK_TYPE.DHCP
     else:
         mode = INTERFACE_LINK_TYPE.LINK_UP
     ip_address = factory.make_ip_address()
     self.patch_autospec(Interface, "link_subnet")
     handler.link_subnet({
         "system_id": node.system_id,
         "interface_id": interface.id,
         "subnet": subnet.id,
         "ip_assignment": ip_assignment,
         "ip_address": ip_address,
         })
     if ip_assignment == DEVICE_IP_ASSIGNMENT_TYPE.STATIC:
         self.assertThat(
             Interface.link_subnet,
             MockCalledOnceWith(
                 ANY, mode, subnet, ip_address=ip_address))
     else:
         self.assertThat(Interface.link_subnet, MockNotCalled())