Esempio n. 1
0
 def test_machine_asdict(self):
     hostname = factory.make_name('hostname')
     cores = random.randint(1, 8)
     cpu_speed = random.randint(1000, 2000)
     memory = random.randint(4096, 8192)
     interfaces = [RequestedMachineInterface() for _ in range(3)]
     block_devices = [
         RequestedMachineBlockDevice(
             size=random.randint(512, 1024),
             tags=[factory.make_name('tag') for _ in range(3)])
         for _ in range(3)
     ]
     machine = RequestedMachine(hostname=hostname,
                                architecture='amd64/generic',
                                cores=cores,
                                cpu_speed=cpu_speed,
                                memory=memory,
                                interfaces=interfaces,
                                block_devices=block_devices)
     self.assertThat(
         machine.asdict(),
         MatchesDict({
             "hostname":
             Equals(hostname),
             "architecture":
             Equals("amd64/generic"),
             "cores":
             Equals(cores),
             "cpu_speed":
             Equals(cpu_speed),
             "memory":
             Equals(memory),
             "interfaces":
             MatchesListwise([
                 MatchesDict({
                     "attach_name":
                     Equals(interface.attach_name),
                     "attach_type":
                     Equals(interface.attach_type),
                     "attach_options":
                     Equals(interface.attach_options),
                 }) for interface in interfaces
             ]),
             "block_devices":
             MatchesListwise([
                 MatchesDict({
                     "size": Equals(block_device.size),
                     "tags": Equals(block_device.tags),
                 }) for block_device in block_devices
             ]),
         }))
Esempio n. 2
0
 def test_machine_asdict(self):
     hostname = factory.make_name("hostname")
     cores = random.randint(1, 8)
     cpu_speed = random.randint(1000, 2000)
     memory = random.randint(4096, 8192)
     interfaces = [RequestedMachineInterface() for _ in range(3)]
     known_host_interfaces = [KnownHostInterface() for _ in range(3)]
     block_devices = [
         RequestedMachineBlockDevice(
             size=random.randint(512, 1024),
             tags=[factory.make_name("tag") for _ in range(3)],
         ) for _ in range(3)
     ]
     machine = RequestedMachine(
         hostname=hostname,
         architecture="amd64/generic",
         cores=cores,
         cpu_speed=cpu_speed,
         memory=memory,
         interfaces=interfaces,
         known_host_interfaces=known_host_interfaces,
         block_devices=block_devices,
     )
     self.assertThat(
         machine.asdict(),
         MatchesDict({
             "hostname":
             Equals(hostname),
             "architecture":
             Equals("amd64/generic"),
             "cores":
             Equals(cores),
             "cpu_speed":
             Equals(cpu_speed),
             "memory":
             Equals(memory),
             "interfaces":
             MatchesListwise([
                 MatchesDict({
                     "ifname":
                     Is(None),
                     "requested_ips":
                     Equals([]),
                     "ip_mode":
                     Is(None),
                     "attach_name":
                     Equals(interface.attach_name),
                     "attach_type":
                     Equals(interface.attach_type),
                     "attach_options":
                     Equals(interface.attach_options),
                 }) for interface in interfaces
             ]),
             "known_host_interfaces":
             MatchesListwise([
                 MatchesDict({
                     "ifname":
                     Equals(known_host_interface.ifname),
                     "attach_type":
                     Equals(known_host_interface.attach_type),
                     "dhcp_enabled":
                     Equals(False),
                 }) for known_host_interface in known_host_interfaces
             ]),
             "block_devices":
             MatchesListwise([
                 MatchesDict({
                     "size": Equals(block_device.size),
                     "tags": Equals(block_device.tags),
                 }) for block_device in block_devices
             ]),
         }),
     )