示例#1
0
    def test_create_ip_not_vlan_ko(self):
        args = ['--hostname', 'server500', '--ip', '10.50.10.10']
        result = self.invoke_with_exceptions(vm.create,
                                             args,
                                             obj=GandiContextHelper(),
                                             input='plokiploki\nplokiploki\n')
        self.assertEqual(
            re.sub(r'\[#+\]', '[###]', result.output.strip()), """\
password: \nRepeat for confirmation: \n\
--ip can't be used without --vlan.""")

        self.assertEqual(result.exit_code, 0)
示例#2
0
    def choices(self):
        """ Retrieve choices from API if possible"""
        if not self._choices:
            gandi = self.gandi or GandiContextHelper()
            self._choices = self._get_choices(gandi)
            if not self._choices:
                api = gandi.get_api_connector()
                gandi.echo('Please check that you are connecting to the good '
                           "api '%s' and that it's running." % (api.host))
                sys.exit(1)

        return self._choices
示例#3
0
    def test_create_datacenter_closed(self):
        args = ['--datacenter', 'US-BA1']
        result = self.invoke_with_exceptions(paas.create, args,
                                             obj=GandiContextHelper(),
                                             input='ploki\nploki\n')

        output = re.sub(r'\[#+\]', '[###]', result.output.strip())

        self.assertEqual(re.sub(r'paas\d+', 'paas', output), """\
Error: /!\ Datacenter US-BA1 is closed, please choose another datacenter.""")

        self.assertEqual(result.exit_code, 1)
示例#4
0
    def test_update_gateway_multiple_ips(self):
        args = ['pouet', '--name', 'chocolat', '--gateway', 'server02']

        result = self.invoke_with_exceptions(vlan.update,
                                             args,
                                             obj=GandiContextHelper())

        self.assertEqual(
            re.sub(r'\[#+\]', '[###]', result.output.strip()), """\
This vm has two ips in the vlan, don't know which one to choose \
(213.167.231.3, 192.168.232.252)""")

        self.assertEqual(result.exit_code, 0)
示例#5
0
    def test_update_password(self):
        args = ['paas_owncloud', '--password']
        result = self.invoke_with_exceptions(paas.update, args,
                                             obj=GandiContextHelper(),
                                             input='ploki\nploki\n')

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
password: \nRepeat for confirmation: \n\
Updating your PaaS instance.
\rProgress: [###] 100.00%  00:00:00""")

        self.assertEqual(result.exit_code, 0)
示例#6
0
    def test_create_datacenter_closed(self):
        args = [
            '--name', 'newdisk', '--size', '5G', '--datacenter', 'US-BA1',
            '--snapshotprofile', '3'
        ]
        result = self.invoke_with_exceptions(disk.create,
                                             args,
                                             obj=GandiContextHelper())

        self.assertEqual(
            re.sub(r'\[#+\]', '[###]', result.output.strip()), """\
Error: /!\ Datacenter US-BA1 is closed, please choose another datacenter.""")
        self.assertEqual(result.exit_code, 1)
示例#7
0
    def test_create_background(self):
        args = ['--name', 'testvlanbg', '--bg']
        result = self.invoke_with_exceptions(vlan.create,
                                             args,
                                             obj=GandiContextHelper())

        self.assertEqual(result.output.strip(), """\
{'id': 200, 'step': 'WAIT'}""")

        self.assertEqual(result.exit_code, 0)
        params = self.api_calls['hosting.vlan.create'][0][0]
        self.assertEqual(params['datacenter_id'], 3)
        self.assertEqual(params['name'], 'testvlanbg')
示例#8
0
    def test_create_default_background(self):
        args = ['--bg']
        result = self.invoke_with_exceptions(disk.create, args,
                                             obj=GandiContextHelper())

        self.assertEqual(result.output.strip(), """\
id        : 200
step      : WAIT""")
        self.assertEqual(result.exit_code, 0)
        params = self.api_calls['hosting.disk.create'][0][0]
        self.assertEqual(params['type'], 'data')
        self.assertEqual(params['size'], 3072)
        self.assertTrue(params['name'].startswith('vdi'))
示例#9
0
    def test_update_gateway_vm_unknown(self):
        args = ['pouet', '--name', 'chocolat',
                '--gateway', 'server01',
                '--bandwidth', '204800']

        result = self.invoke_with_exceptions(vlan.update, args,
                                             obj=GandiContextHelper())

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
Can't find 'server01' in 'pouet' vlan""")

        self.assertEqual(result.exit_code, 0)
示例#10
0
    def test_create_params_ip_ko(self):
        args = [
            '--datacenter', 'FR', '--bandwidth', '51200', '--ip-version', '4',
            '--ip', '10.50.10.10'
        ]
        result = self.invoke_with_exceptions(ip.create,
                                             args,
                                             obj=GandiContextHelper())

        self.assertEqual(re.sub(r'\[#+\]', '[###]', result.output.strip()),
                         """\
You must have a --vlan when giving an --ip.""")
        self.assertEqual(result.exit_code, 0)
示例#11
0
    def test_create_source(self):
        args = ['--source', 'sys_server01']
        result = self.invoke_with_exceptions(disk.create, args,
                                             obj=GandiContextHelper())

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
Creating your disk.
\rProgress: [###] 100.00%  00:00:00""")
        self.assertEqual(result.exit_code, 0)
        params, disk_id = self.api_calls['hosting.disk.create_from'][0]
        self.assertEqual(params['type'], 'data')
        self.assertTrue(params['name'].startswith('vdi'))
        self.assertEqual(disk_id, 4969249)
示例#12
0
    def test_create_name(self):
        args = ['--name', '123456']
        result = self.invoke_with_exceptions(paas.create, args,
                                             obj=GandiContextHelper(),
                                             input='ploki\nploki\n')

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
password: \nRepeat for confirmation: \n\
Creating your PaaS instance.
\rProgress: [###] 100.00%  00:00:00  \n\
Your PaaS instance 123456 has been created.""")

        self.assertEqual(result.exit_code, 0)
示例#13
0
    def test_create_params_attach_ko(self):
        args = [
            '--datacenter', 'US', '--bandwidth', '51200', '--ip-version', '4',
            '--attach', 'server01'
        ]
        result = self.invoke_with_exceptions(ip.create,
                                             args,
                                             obj=GandiContextHelper())

        self.assertEqual(
            re.sub(r'\[#+\]', '[###]', result.output.strip()), """\
The datacenter you provided does not match the datacenter of the \
vm you want to attach to.""")
        self.assertEqual(result.exit_code, 0)
示例#14
0
    def test_create_datacenter_closed(self):
        args = [
            '--name', 'testvlan', '--datacenter', 'US-BA1', '--subnet',
            '10.7.70.0/24', '--gateway', '10.7.70.254'
        ]
        result = self.invoke_with_exceptions(vlan.create,
                                             args,
                                             obj=GandiContextHelper())

        self.assertEqual(
            re.sub(r'\[#+\]', '[###]', result.output.strip()), """\
Error: /!\ Datacenter US-BA1 is closed, please choose another datacenter.""")

        self.assertEqual(result.exit_code, 1)
示例#15
0
    def test_delete(self):
        args = ['intranet']
        result = self.invoke_with_exceptions(vlan.delete,
                                             args,
                                             input='y\n',
                                             obj=GandiContextHelper())

        self.assertEqual(
            re.sub(r'\[#+\]', '[###]', result.output.strip()), """\
Are you sure to delete vlan 'intranet'? [y/N]: y
Deleting your vlan.
\rProgress: [###] 100.00%  00:00:00""")

        self.assertEqual(result.exit_code, 0)
示例#16
0
    def test_create_datacenter_closed(self):
        args = [
            '--datacenter', 'US-BA1', '--bandwidth', '51200', '--ip-version',
            '6'
        ]
        result = self.invoke_with_exceptions(ip.create,
                                             args,
                                             obj=GandiContextHelper())

        self.assertEqual(
            re.sub(r'\[#+\]', '[###]', result.output.strip()), """\
Error: /!\ Datacenter US-BA1 is closed, please choose another datacenter.""")

        self.assertEqual(result.exit_code, 1)
示例#17
0
    def test_create_background_ok(self):
        args = ['--hostname', 'server500', '--background']
        result = self.invoke_with_exceptions(vm.create, args,
                                             obj=GandiContextHelper(),
                                             input='plokiploki\nplokiploki\n')
        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
password: \nRepeat for confirmation: \n* root user will be created.
* Configuration used: 1 cores, 256Mb memory, ip v6, image Debian 8\
, hostname: server500, datacenter: FR-SD5
* IAAS backend is now creating your VM and its associated resources in the \
background.""")

        self.assertEqual(result.exit_code, 0)
示例#18
0
    def test_create_default_ok(self):
        args = []
        result = self.invoke_with_exceptions(disk.create, args,
                                             obj=GandiContextHelper())

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
Creating your disk.
\rProgress: [###] 100.00%  00:00:00""")
        self.assertEqual(result.exit_code, 0)
        params = self.api_calls['hosting.disk.create'][0][0]
        self.assertEqual(params['type'], 'data')
        self.assertEqual(params['size'], 3072)
        self.assertTrue(params['name'].startswith('vdi'))
示例#19
0
    def test_create_default_hostname_ok(self):
        args = ['--hostname', 'server500']
        result = self.invoke_with_exceptions(vm.create, args,
                                             obj=GandiContextHelper(),
                                             input='plokiploki\nplokiploki\n')
        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
password: \nRepeat for confirmation: \n* root user will be created.
* Configuration used: 1 cores, 256Mb memory, ip v6, image Debian 8\
, hostname: server500, datacenter: FR-SD5
Creating your Virtual Machine server500.
\rProgress: [###] 100.00%  00:00:00  \n\
Your Virtual Machine server500 has been created.""")

        self.assertEqual(result.exit_code, 0)
示例#20
0
    def test_create_params(self):
        args = ['--name', 'newdisk', '--size', '5G', '--datacenter', 'FR',
                '--snapshotprofile', '3']
        result = self.invoke_with_exceptions(disk.create, args,
                                             obj=GandiContextHelper())

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
Creating your disk.
\rProgress: [###] 100.00%  00:00:00""")
        self.assertEqual(result.exit_code, 0)
        params = self.api_calls['hosting.disk.create'][0][0]
        self.assertEqual(params['datacenter_id'], 1)
        self.assertEqual(params['size'], 5120)
        self.assertEqual(params['name'], 'newdisk')
        self.assertEqual(params['snapshot_profile'], 3)
示例#21
0
    def test_update(self):
        args = ['pouet', '--name', 'chocolat',
                '--gateway', '10.7.70.254',
                '--bandwidth', '204800']

        result = self.invoke_with_exceptions(vlan.update, args,
                                             obj=GandiContextHelper())

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
Updating your vlan.""")

        self.assertEqual(result.exit_code, 0)
        params = self.api_calls['hosting.vlan.update'][0][1]
        self.assertEqual(params['name'], 'chocolat')
        self.assertEqual(params['gateway'], '10.7.70.254')
示例#22
0
    def test_create_dc_code_ok(self):
        args = ['--datacenter', 'FR-SD2']
        result = self.invoke_with_exceptions(vm.create, args,
                                             obj=GandiContextHelper(),
                                             input='plokiploki\nplokiploki\n')
        output = re.sub(r'\[#+\]', '[###]', result.output.strip())

        self.assertEqual(re.sub(r'vm\d+', 'vm', output), """\
password: \nRepeat for confirmation: \n* root user will be created.
* Configuration used: 1 cores, 256Mb memory, ip v6, image Debian 7 64 bits \
(HVM), hostname: vm, datacenter: FR-SD2
Creating your Virtual Machine vm.
\rProgress: [###] 100.00%  00:00:00  \n\
Your Virtual Machine vm has been created.""")

        self.assertEqual(result.exit_code, 0)
示例#23
0
    def test_create_name_vhost_ssl(self):
        self.maxDiff = None
        args = ['--name', '123456', '--vhosts', 'inter.net', '--ssl']
        with mock.patch('gandi.cli.modules.vhost.os.chdir',
                        create=True) as mock_chdir:
            mock_chdir.return_value = mock.MagicMock()

            result = self.invoke_with_exceptions(paas.create, args,
                                                 obj=GandiContextHelper(),
                                                 input='ploki\nploki\n')

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
password: \nRepeat for confirmation: \n\
Please give the private key for certificate id 706 (CN: inter.net)""")

        self.assertEqual(result.exit_code, 0)
示例#24
0
    def test_create_sshkey_ok(self):
        args = ['--sshkey', 'mysecretkey']
        result = self.invoke_with_exceptions(vm.create, args,
                                             obj=GandiContextHelper())
        output = re.sub(r'\[#+\]', '[###]', result.output.strip())

        self.assertEqual(re.sub(r'vm\d+', 'vm', output), """\
* root user will be created.
* SSH key authorization will be used.
* No password supplied for vm (required to enable emergency web console \
access).
* Configuration used: 1 cores, 256Mb memory, ip v6, image Debian 8\
, hostname: vm, datacenter: FR-SD5
Creating your Virtual Machine vm.
\rProgress: [###] 100.00%  00:00:00  \n\
Your Virtual Machine vm has been created.""")

        self.assertEqual(result.exit_code, 0)
示例#25
0
    def test_create_datacenter_limited(self):
        args = ['--name', 'newdisk', '--size', '5G', '--datacenter', 'FR-SD2',
                '--snapshotprofile', '3']
        result = self.invoke_with_exceptions(disk.create, args,
                                             obj=GandiContextHelper())

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
/!\ Datacenter FR-SD2 will be closed on 25/12/2017, please consider using \
another datacenter.
Creating your disk.
\rProgress: [###] 100.00%  00:00:00""")
        self.assertEqual(result.exit_code, 0)
        params = self.api_calls['hosting.disk.create'][0][0]
        self.assertEqual(params['datacenter_id'], 1)
        self.assertEqual(params['size'], 5120)
        self.assertEqual(params['name'], 'newdisk')
        self.assertEqual(params['snapshot_profile'], 3)
示例#26
0
    def test_create(self):
        args = ['*****@*****.**', '--quota', '2', '--fallback',
                '*****@*****.**', '--alias', '*****@*****.**']
        result = self.invoke_with_exceptions(mail.create, args,
                                             obj=GandiContextHelper(),
                                             input='plokiploki\nplokiploki\n')

        self.assertEqual(result.output, """password: \
\nRepeat for confirmation: \
\nCreating your mailbox.
Creating aliases.
""")

        self.assertEqual(result.exit_code, 0)
        params = self.api_calls['domain.mailbox.create'][0][2]
        self.assertEqual(params['password'], 'plokiploki')
        self.assertEqual(params['quota'], 2)
        self.assertEqual(params['fallback_email'], '*****@*****.**')
示例#27
0
    def test_create_default(self):
        args = []
        result = self.invoke_with_exceptions(ip.create, args,
                                             obj=GandiContextHelper())

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
Creating your iface.
\rProgress: [###] 100.00%  00:00:00  \
\nYour iface has been created with the following IP addresses:
ip4:\t95.142.160.181
ip6:\t2001:4b98:dc0:47:216:3eff:feb2:3862""")

        self.assertEqual(result.exit_code, 0)
        params = self.api_calls['hosting.iface.create'][0][0]
        self.assertEqual(params['datacenter_id'], 3)
        self.assertEqual(params['bandwidth'], 102400)
        self.assertEqual(params['ip_version'], 4)
示例#28
0
    def test_create_vm(self):
        args = ['--vm', 'server01']
        result = self.invoke_with_exceptions(disk.create, args,
                                             obj=GandiContextHelper())

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
/!\ VM server01 datacenter will be used instead of FR-SD3.
Creating your disk.
\rProgress: [###] 100.00%  00:00:00  \
\nAttaching your disk.
\rProgress: [###] 100.00%  00:00:00""")
        self.assertEqual(result.exit_code, 0)
        params = self.api_calls['hosting.disk.create'][0][0]
        self.assertEqual(params['type'], 'data')
        self.assertEqual(params['size'], 3072)
        self.assertEqual(params['datacenter_id'], 1)
        self.assertTrue(params['name'].startswith('vdi'))
示例#29
0
    def test_create(self):
        args = ['--name', 'testvlan', '--datacenter', 'FR-SD2',
                '--subnet', '10.7.70.0/24', '--gateway', '10.7.70.254']
        result = self.invoke_with_exceptions(vlan.create, args,
                                             obj=GandiContextHelper())

        self.assertEqual(re.sub(r'\[#+\]', '[###]',
                                result.output.strip()), """\
Creating your vlan.
\rProgress: [###] 100.00%  00:00:00  \
\nYour vlan testvlan has been created.""")

        self.assertEqual(result.exit_code, 0)
        params = self.api_calls['hosting.vlan.create'][0][0]
        self.assertEqual(params['datacenter_id'], 1)
        self.assertEqual(params['subnet'], '10.7.70.0/24')
        self.assertEqual(params['name'], 'testvlan')
        self.assertEqual(params['gateway'], '10.7.70.254')
示例#30
0
    def test_create_datacenter_limited(self):
        args = ['--datacenter', 'FR-SD2']
        result = self.invoke_with_exceptions(vm.create, args,
                                             obj=GandiContextHelper(),
                                             input='plokiploki\nplokiploki\n')
        output = re.sub(r'\[#+\]', '[###]', result.output.strip())

        self.assertEqual(re.sub(r'vm\d+', 'vm', output), """\
/!\ Datacenter FR-SD2 will be closed on 25/12/2017, please consider \
using another datacenter.
password: \nRepeat for confirmation: \n\
* root user will be created.
* Configuration used: 1 cores, 256Mb memory, ip v6, image Debian 8\
, hostname: vm, datacenter: FR-SD2
Creating your Virtual Machine vm.
\rProgress: [###] 100.00%  00:00:00  \n\
Your Virtual Machine vm has been created.""")

        self.assertEqual(result.exit_code, 0)