Example #1
0
    def test__compose_sends_default_storage_pool_id(self):
        request = MagicMock()
        pod = make_pod_with_hints()

        # Mock the RPC client.
        client = MagicMock()
        mock_getClient = self.patch(pods_module, "getClientFromIdentifiers")
        mock_getClient.return_value = succeed(client)

        # Mock the result of the composed machine.
        composed_machine, pod_hints = self.make_compose_machine_result(pod)
        mock_compose_machine = self.patch(pods_module, "compose_machine")
        mock_compose_machine.return_value = succeed(
            (composed_machine, pod_hints))

        # Mock start_commissioning so it doesn't use post commit hooks.
        self.patch(Machine, "start_commissioning")

        form = ComposeMachineForm(data={}, request=request, pod=pod)
        self.assertTrue(form.is_valid())
        form.compose()
        self.assertThat(mock_compose_machine, MockCalledOnceWith(
            ANY, pod.power_type, {
                'default_storage_pool_id': pod.default_storage_pool.pool_id,
            },
            form.get_requested_machine(), pod_id=pod.id, name=pod.name))
Example #2
0
 def test__get_requested_machine_handles_no_tags_in_storage(self):
     request = MagicMock()
     pod = make_pod_with_hints()
     disk_1 = random.randint(8, 16) * (1000 ** 3)
     disk_2 = random.randint(8, 16) * (1000 ** 3)
     storage = 'root:%d,extra:%d' % (
         disk_1 // (1000 ** 3),
         disk_2 // (1000 ** 3))
     form = ComposeMachineForm(data={
         'storage': storage,
     }, request=request, pod=pod)
     self.assertTrue(form.is_valid(), form.errors)
     request_machine = form.get_requested_machine()
     self.assertThat(request_machine, MatchesAll(
         IsInstance(RequestedMachine),
         MatchesStructure(
             block_devices=MatchesListwise([
                 MatchesAll(
                     IsInstance(RequestedMachineBlockDevice),
                     MatchesStructure(
                         size=Equals(disk_1), tags=Equals([]))),
                 MatchesAll(
                     IsInstance(RequestedMachineBlockDevice),
                     MatchesStructure(
                         size=Equals(disk_2), tags=Equals([]))),
                 ]))))
Example #3
0
 def test__get_requested_machine_uses_passed_values(self):
     request = MagicMock()
     pod = make_pod_with_hints()
     architecture = random.choice(pod.architectures)
     cores = random.randint(1, pod.hints.cores)
     memory = random.randint(1024, pod.hints.memory)
     cpu_speed = random.randint(300, pod.hints.cpu_speed)
     disk_1 = random.randint(8, 16) * (1000 ** 3)
     disk_1_tags = [
         factory.make_name('tag')
         for _ in range(3)
     ]
     disk_2 = random.randint(8, 16) * (1000 ** 3)
     disk_2_tags = [
         factory.make_name('tag')
         for _ in range(3)
     ]
     storage = 'root:%d(%s),extra:%d(%s)' % (
         disk_1 // (1000 ** 3), ','.join(disk_1_tags),
         disk_2 // (1000 ** 3), ','.join(disk_2_tags))
     form = ComposeMachineForm(data={
         'architecture': architecture,
         'cores': cores,
         'memory': memory,
         'cpu_speed': cpu_speed,
         'storage': storage,
     }, request=request, pod=pod)
     self.assertTrue(form.is_valid(), form.errors)
     request_machine = form.get_requested_machine()
     self.assertThat(request_machine, MatchesAll(
         IsInstance(RequestedMachine),
         MatchesStructure(
             architecture=Equals(architecture),
             cores=Equals(cores),
             memory=Equals(memory),
             cpu_speed=Equals(cpu_speed),
             block_devices=MatchesListwise([
                 MatchesAll(
                     IsInstance(RequestedMachineBlockDevice),
                     MatchesStructure(
                         size=Equals(disk_1), tags=Equals(disk_1_tags))),
                 MatchesAll(
                     IsInstance(RequestedMachineBlockDevice),
                     MatchesStructure(
                         size=Equals(disk_2), tags=Equals(disk_2_tags))),
                 ]),
             interfaces=MatchesListwise([
                 IsInstance(RequestedMachineInterface)]))))
Example #4
0
 def test__get_requested_machine_uses_all_initial_values(self):
     request = MagicMock()
     pod = make_pod_with_hints()
     form = ComposeMachineForm(data={}, request=request, pod=pod)
     self.assertTrue(form.is_valid())
     request_machine = form.get_requested_machine()
     self.assertThat(request_machine, MatchesAll(
         IsInstance(RequestedMachine),
         MatchesStructure(
             architecture=Equals(pod.architectures[0]),
             cores=Equals(1),
             memory=Equals(1024),
             cpu_speed=Is(None),
             block_devices=MatchesListwise([
                 MatchesAll(
                     IsInstance(RequestedMachineBlockDevice),
                     MatchesStructure(size=Equals(8 * (1000 ** 3))))]),
             interfaces=MatchesListwise([
                 IsInstance(RequestedMachineInterface)]))))