示例#1
0
    def test_create_server_with_export(self, export_to_template):
        args = {
            '--chassis': 999,
            '--hostname': 'test',
            '--domain': 'example.com',
            '--datacenter': 'TEST00',
            '--cpu': False,
            '--network': '100',
            '--disk': ['1000_DRIVE', '1000_DRIVE'],
            '--os': 'UBUNTU_12_64_MINIMAL',
            '--memory': False,
            '--controller': False,
            '--test': True,
            '--template': None,
            '--key': [1234],
            '--export': 'test_file.txt',
        }

        runnable = server.CreateServer(client=self.client)

        expected = args.copy()
        del (expected['--export'])

        runnable.execute(args)

        export_to_template.assert_called_with('test_file.txt',
                                              expected,
                                              exclude=['--wait', '--test'])
示例#2
0
    def test_create_server_failures(self):

        # This is missing a required argument
        args = {
            '--hostname': 'test',
            '--domain': 'example.com',
            '--datacenter': 'TEST00',
            '--cpu': False,
            '--disk': ['1000_DRIVE', '1000_DRIVE'],
            '--os': 'UBUNTU_12_64_MINIMAL',
            '--memory': False,
            '--controller': False,
            '--test': True,
            '--export': None,
            '--template': None,
        }

        runnable = server.CreateServer(client=self.client)

        # Verify that ArgumentError is properly raised on error
        self.assertRaises(exceptions.ArgumentError, runnable.execute, args)

        # This contains an invalid network argument
        args['--chassis'] = 999
        args['--network'] = 9999

        # Verify that CLIAbort is properly raised on error
        self.assertRaises(exceptions.CLIAbort, runnable.execute, args)

        # This contains an invalid operating system argument
        args['--network'] = '100'
        args['--os'] = 'nope'

        # Verify that CLIAbort is properly raised on error
        self.assertRaises(exceptions.CLIAbort, runnable.execute, args)
示例#3
0
 def test_get_default_value_returns_none_for_unknown_category(self):
     option_mock = {'categories': {'cat1': []}}
     runnable = server.CreateServer()
     output = runnable._get_default_value(option_mock, 'nope')
     self.assertEqual(None, output)
示例#4
0
    def test_create_server_for_bmc(self, bmpi, packages):
        args = {
            '--chassis': '1099',
            '--hostname': 'test',
            '--domain': 'example.com',
            '--datacenter': 'TEST00',
            '--cpu': '2',
            '--network': '100',
            '--disk': ['250_SATA_II', '250_SATA_II'],
            '--os': 'UBUNTU_12_64_MINIMAL',
            '--memory': '2',
            '--test': True,
            '--export': None,
            '--template': None,
            '--key': [1234, 456],
            '--vlan_public': 10234,
            '--vlan_private': 20468,
            '--postinstall': 'http://somescript.foo/myscript.sh',
            '--billing': 'hourly',
        }

        test_data = [
            (1099, 'Bare Metal Instance'),
        ]
        packages.return_value = test_data

        bmpi.return_value = '1099'

        runnable = server.CreateServer(client=self.client)

        # First, test the --test flag
        with mock.patch('SoftLayer.HardwareManager'
                        '.verify_order') as verify_mock:
            verify_mock.return_value = {
                'prices': [{
                    'recurringFee': 0.0,
                    'setupFee': 0.0,
                    'item': {
                        'description': 'First Item'
                    },
                }, {
                    'recurringFee': 25.0,
                    'setupFee': 0.0,
                    'item': {
                        'description': 'Second Item'
                    },
                }]
            }
            output = runnable.execute(args)

            expected = [[{
                'Item': 'First Item',
                'cost': '0.00'
            }, {
                'Item': 'Second Item',
                'cost': '25.00'
            }, {
                'Item': 'Total monthly cost',
                'cost': '25.00'
            }], '']

            self.assertEqual(expected,
                             formatting.format_output(output, 'python'))

            # Make sure we can order without specifying the disk as well
            args['--disk'] = []

            output = runnable.execute(args)

            self.assertEqual(expected,
                             formatting.format_output(output, 'python'))

            # Test explicitly setting a RAID configuration
            args['--controller'] = 'RAID0'

            output = runnable.execute(args)

            self.assertEqual(expected,
                             formatting.format_output(output, 'python'))

        # Now test ordering
        with mock.patch('SoftLayer.HardwareManager.place_order') as order_mock:
            order_mock.return_value = {
                'orderId': 98765,
                'orderDate': '2013-08-02 15:23:47'
            }

            args['--test'] = False
            args['--really'] = True

            output = runnable.execute(args)

            expected = {'id': 98765, 'created': '2013-08-02 15:23:47'}
            self.assertEqual(expected,
                             formatting.format_output(output, 'python'))

        # Finally, test cancelling the process
        with mock.patch('SoftLayer.CLI.formatting.confirm') as confirm:
            confirm.return_value = False

            args['--really'] = False

            self.assertRaises(exceptions.CLIAbort, runnable.execute, args)