def test_update_vms_in_group(self):
        vm_1 = FakeAwsVirtualMachine()
        vm_2 = FakeAwsVirtualMachine()
        vm_3 = FakeAwsVirtualMachine()
        vm_group = [vm_1, vm_2, vm_3]

        capacity_reservation = aws_capacity_reservation.AwsCapacityReservation(
            vm_group)
        capacity_reservation.capacity_reservation_id = 'foo'

        capacity_reservation._UpdateVmsInGroup('foo', 'us-west-1z')
        for vm in vm_group:
            self.assertEqual('foo', vm.capacity_reservation_id)
            self.assertEqual('us-west-1z', vm.zone)
            self.assertEqual('us-west-1z', vm.network.zone)
    def test_delete(self):
        vm_group = [FakeAwsVirtualMachine()]
        capacity_reservation = aws_capacity_reservation.AwsCapacityReservation(
            vm_group)
        capacity_reservation.capacity_reservation_id = 'foo'

        with mock.patch(vm_util.__name__ + '.IssueCommand') as issue_command:
            capacity_reservation._Delete()
            command_string = ' '.join(issue_command.call_args[0][0])

            expected_command = (
                'aws --output json ec2 cancel-capacity-reservation '
                '--capacity-reservation-id=foo --region=us-west-1')
            self.assertEqual(issue_command.call_count, 1)
            self.assertIn(expected_command, command_string)
示例#3
0
    def test_create(self):
        vm_group = [FakeAwsVirtualMachine()]
        capacity_reservation = aws_capacity_reservation.AwsCapacityReservation(
            vm_group)

        with mock.patch(vm_util.__name__ + '.IssueCommand',
                        return_value=(CREATE_STDOUT_SUCCESSFUL, '',
                                      0)) as issue_command:
            capacity_reservation._Create()
            command_string = ' '.join(issue_command.call_args[0][0])

            expected_command = (
                'aws --output json ec2 create-capacity-reservation '
                '--instance-type=fake_machine_type '
                '--instance-platform=Linux/UNIX --availability-zone=us-west-1a '
                '--instance-count=1 --instance-match-criteria=targeted '
                '--region=us-west-1 --end-date-type=limited --end-date=%s' %
                TIMEOUT_UTC)

            self.assertEqual(issue_command.call_count, 1)
            self.assertIn(expected_command, command_string)