Ejemplo n.º 1
0
    def test_batchai_update_nodes_information(self):
        """Test updating of nodes information."""
        params = ClusterCreateParameters(
            location='eastus',
            vm_size='STANDARD_D1',
            user_account_settings=UserAccountSettings(
                admin_user_name='name', admin_user_password='******'))
        # Update to autoscale Ubuntu DSVM.
        update_nodes_information(params, 'ubuntudsvm', 'Standard_NC6', 1, 3)
        self.assertEquals(params.vm_size, 'Standard_NC6')
        self.assertEquals(
            params.virtual_machine_configuration.image_reference,
            ImageReference('microsoft-ads', 'linux-data-science-vm-ubuntu',
                           'linuxdsvmubuntu'))
        self.assertEquals(params.scale_settings,
                          ScaleSettings(auto_scale=AutoScaleSettings(1, 3)))

        # Update to manual scale Ubuntu LTS.
        update_nodes_information(params, 'UbuntuLTS', 'Standard_NC6', 2, 2)
        self.assertEquals(params.vm_size, 'Standard_NC6')
        self.assertEquals(
            params.virtual_machine_configuration.image_reference,
            ImageReference('Canonical', 'UbuntuServer', '16.04-LTS'))
        self.assertEquals(params.scale_settings,
                          ScaleSettings(manual=ManualScaleSettings(2)))

        # Update image.
        update_nodes_information(params, 'UbuntuDsvm', None, 0, None)
        self.assertEquals(params.vm_size, 'Standard_NC6')
        self.assertEquals(
            params.virtual_machine_configuration.image_reference,
            ImageReference('microsoft-ads', 'linux-data-science-vm-ubuntu',
                           'linuxdsvmubuntu'))
        self.assertEquals(params.scale_settings,
                          ScaleSettings(manual=ManualScaleSettings(2)))

        # Update nothing.
        update_nodes_information(params, None, None, 0, None)
        self.assertEquals(params.vm_size, 'Standard_NC6')
        self.assertEquals(
            params.virtual_machine_configuration.image_reference,
            ImageReference('microsoft-ads', 'linux-data-science-vm-ubuntu',
                           'linuxdsvmubuntu'))
        self.assertEquals(params.scale_settings,
                          ScaleSettings(manual=ManualScaleSettings(2)))

        # Wrong image.
        with self.assertRaises(CLIError):
            update_nodes_information(params, 'unsupported', None, 0, None)

        # No VM size.
        params.vm_size = None
        with self.assertRaises(CLIError):
            update_nodes_information(params, 'unsupported', None, 0, None)

        # No scale settings.
        params.vm_size = 'Standard_NC6'
        params.scale_settings = None
        with self.assertRaises(CLIError):
            update_nodes_information(params, None, None, 0, None)
Ejemplo n.º 2
0
    def test_batchai_update_nodes_information(self):
        params = ClusterCreateParameters(location='southcentralus', vm_size='STANDARD_D1',
                                         user_account_settings=UserAccountSettings(admin_user_name='name',
                                                                                   admin_user_password='******'))
        # Update to autoscale Ubuntu DSVM.
        result = _update_nodes_information(params, 'ubuntudsvm', None, 'Standard_NC6', 'dedicated', None, 1, 3)
        self.assertEquals(result.vm_size, 'Standard_NC6')
        self.assertEquals(result.vm_priority, 'dedicated')
        self.assertEquals(
            ImageReference(publisher='microsoft-ads', offer='linux-data-science-vm-ubuntu', sku='linuxdsvmubuntu'),
            result.virtual_machine_configuration.image_reference)
        self.assertEquals(result.scale_settings,
                          ScaleSettings(auto_scale=AutoScaleSettings(minimum_node_count=1, maximum_node_count=3)))

        # Update to manual scale Ubuntu LTS.
        result = _update_nodes_information(params, 'UbuntuLTS', None, 'Standard_NC6', '', None, 2, 2)
        self.assertEquals(result.vm_size, 'Standard_NC6')
        self.assertEquals(result.vm_priority, 'dedicated')
        self.assertEquals(ImageReference(
            publisher='Canonical', offer='UbuntuServer', sku='16.04-LTS'),
            result.virtual_machine_configuration.image_reference
        )
        self.assertEquals(result.scale_settings, ScaleSettings(
            manual=ManualScaleSettings(target_node_count=2)))

        # Update to manual scale Ubuntu LTS.
        result = _update_nodes_information(params, 'UbuntuLTS', None, 'Standard_NC6', '', 2, 2, 2)
        self.assertEquals(result.vm_size, 'Standard_NC6')
        self.assertEquals(result.vm_priority, 'dedicated')
        self.assertEquals(
            ImageReference(publisher='Canonical', offer='UbuntuServer', sku='16.04-LTS'),
            result.virtual_machine_configuration.image_reference)
        self.assertEquals(result.scale_settings, ScaleSettings(manual=ManualScaleSettings(target_node_count=2)))

        # Update to manual scale Ubuntu LTS.
        result = _update_nodes_information(params, 'UbuntuLTS', None, 'Standard_NC6', '', 2, None, None)
        self.assertEquals(result.vm_size, 'Standard_NC6')
        self.assertEquals(result.vm_priority, 'dedicated')
        self.assertEquals(
            ImageReference(publisher='Canonical', offer='UbuntuServer', sku='16.04-LTS'),
            result.virtual_machine_configuration.image_reference
        )
        self.assertEquals(result.scale_settings, ScaleSettings(manual=ManualScaleSettings(target_node_count=2)))

        # Update to auto-scale with initial count Ubuntu LTS.
        result = _update_nodes_information(params, 'UbuntuLTS', None, 'Standard_NC6', '', 1, 0, 2)
        self.assertEquals(result.vm_size, 'Standard_NC6')
        self.assertEquals(result.vm_priority, 'dedicated')
        self.assertEquals(
            ImageReference(publisher='Canonical', offer='UbuntuServer', sku='16.04-LTS'),
            result.virtual_machine_configuration.image_reference)
        self.assertEquals(
            ScaleSettings(
                auto_scale=AutoScaleSettings(minimum_node_count=0, maximum_node_count=2, initial_node_count=1)),
            result.scale_settings)

        # Update image.
        params.scale_settings = ScaleSettings(manual=ManualScaleSettings(target_node_count=2))
        result = _update_nodes_information(params, 'UbuntuDsvm', None, None, '', None, None, None)
        self.assertEquals(
            ImageReference(publisher='microsoft-ads', offer='linux-data-science-vm-ubuntu', sku='linuxdsvmubuntu'),
            result.virtual_machine_configuration.image_reference)
        self.assertEquals(result.scale_settings, ScaleSettings(manual=ManualScaleSettings(target_node_count=2)))

        # Update nothing.
        result = _update_nodes_information(params, None, None, None, '', None, None, None)
        self.assertEqual(params, result)

        # Wrong image.
        with self.assertRaisesRegexp(CLIError, 'Unsupported image alias'):
            _update_nodes_information(params, 'unsupported', None, None, '', None, None, None)

        # No VM size.
        params.vm_size = None
        with self.assertRaisesRegexp(CLIError, 'Please provide VM size'):
            _update_nodes_information(params, 'unsupported', None, None, '', None, None, None)

        # No scale settings.
        params.vm_size = 'Standard_NC6'
        params.scale_settings = None
        with self.assertRaisesRegexp(CLIError, 'Please provide scale setting for the cluster'):
            _update_nodes_information(params, None, None, None, '', None, None, None)

        # Error if only min is specified
        with self.assertRaisesRegexp(CLIError, 'You need to either provide both min and max node'):
            _update_nodes_information(params, 'UbuntuLTS', None, 'Standard_NC6', '', 2, 2, None)