def test_deploy_custom_templates(
            self, mock_check_hypervisor_stats, mock_get_key, mock_create_env,
            generate_certs_mock, mock_get_templte_contents,
            mock_process_multiple_env, wait_for_stack_ready_mock,
            mock_remove_known_hosts, mock_keystone_initialize, mock_sleep,
            mock_setup_endpoints, mock_create_overcloudrc,
            mock_generate_overcloud_passwords, mock_update_nodesjson,
            mock_deploy_postconfig):

        arglist = ['--templates', '/home/stack/tripleo-heat-templates']
        verifylist = [
            ('templates', '/home/stack/tripleo-heat-templates'),
        ]

        mock_generate_overcloud_passwords.return_value = self._get_passwords()

        clients = self.app.client_manager
        orchestration_client = clients.rdomanager_oscplugin.orchestration()
        mock_stack = fakes.create_to_dict_mock(
            outputs=[{
                'output_key': 'KeystoneURL',
                'output_value': 'Overcloud endpoint'
            }])
        orchestration_client.stacks.get.return_value = mock_stack

        mock_check_hypervisor_stats.return_value = {
            'count': 4,
            'memory_mb': 4096,
            'vcpus': 8,
        }
        mock_get_key.return_value = "PASSWORD"
        clients.network.api.find_attr.return_value = {"id": "network id"}
        mock_create_env.return_value = "/fake/path"
        mock_process_multiple_env.return_value = [{}, "env"]
        mock_get_templte_contents.return_value = [{}, "template"]
        wait_for_stack_ready_mock.return_value = True

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        self.cmd.take_action(parsed_args)

        args, kwargs = orchestration_client.stacks.update.call_args

        self.assertEqual(args, (orchestration_client.stacks.get().id, ))

        # The parameters output contains lots of output and some is random.
        # So lets just check that it is present
        self.assertTrue('parameters' in kwargs)

        self.assertEqual(kwargs['files'], {})
        self.assertEqual(kwargs['template'], 'template')
        self.assertEqual(kwargs['environment'], 'env')
        self.assertEqual(kwargs['stack_name'], 'overcloud')

        mock_get_templte_contents.assert_called_with(
            '/home/stack/tripleo-heat-templates/overcloud-without-mergepy.yaml'
        )
    def test_tht_scale(self, mock_uuid1, mock_create_cephx_key,
                       mock_check_hypervisor_stats, mock_get_key,
                       mock_create_env, generate_certs_mock,
                       mock_get_templte_contents, mock_process_multiple_env,
                       wait_for_stack_ready_mock,
                       mock_remove_known_hosts, mock_keystone_initialize,
                       mock_sleep, mock_setup_endpoints,
                       mock_create_overcloudrc,
                       mock_generate_overcloud_passwords,
                       mock_update_nodesjson,
                       mock_deploy_postconfig):

        arglist = ['--templates', '--ceph-storage-scale', '3']
        verifylist = [
            ('templates', '/usr/share/openstack-tripleo-heat-templates/'),
        ]

        mock_create_cephx_key.return_value = "cephx_key"
        mock_uuid1.return_value = "uuid"

        mock_generate_overcloud_passwords.return_value = self._get_passwords()

        clients = self.app.client_manager
        orchestration_client = clients.rdomanager_oscplugin.orchestration()
        mock_stack = fakes.create_to_dict_mock(
            outputs=[{
                'output_key': 'KeystoneURL',
                'output_value': 'Overcloud endpoint'
            }]
        )
        orchestration_client.stacks.get.return_value = mock_stack

        mock_check_hypervisor_stats.return_value = {
            'count': 4,
            'memory_mb': 4096,
            'vcpus': 8,
        }
        mock_get_key.return_value = "PASSWORD"
        clients.network.api.find_attr.return_value = {
            "id": "network id"
        }
        mock_create_env.return_value = "/fake/path"
        mock_process_multiple_env.return_value = [{}, "env"]
        mock_get_templte_contents.return_value = [{}, "template"]
        wait_for_stack_ready_mock.return_value = True

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        self.cmd.take_action(parsed_args)

        args, kwargs = orchestration_client.stacks.update.call_args

        self.assertEqual(args, (orchestration_client.stacks.get().id, ))

        expected_parameters = {
            'AdminPassword': '******',
            'AdminToken': 'password',
            'BlockStorageImage': 'overcloud-full',
            'CeilometerMeteringSecret': 'password',
            'CeilometerPassword': '******',
            'CephStorageCount': 3,
            'CephStorageImage': 'overcloud-full',
            'CinderISCSIHelper': 'lioadm',
            'CinderPassword': '******',
            'CloudName': 'overcloud',
            'controllerImage': 'overcloud-full',
            'Debug': 'True',
            'ExtraConfig': '{}',
            'GlancePassword': '******',
            'HeatPassword': '******',
            'HeatStackDomainAdminPassword': '******',
            'HypervisorNeutronPhysicalBridge': 'br-ex',
            'HypervisorNeutronPublicInterface': 'nic1',
            'NeutronAllowL3AgentFailover': False,
            'NeutronBridgeMappings': 'datacentre:br-ex',
            'NeutronControlPlaneID': 'network id',
            'NeutronDhcpAgentsPerNetwork': 3,
            'NeutronDnsmasqOptions': 'dhcp-option-force=26,1400',
            'NeutronFlatNetworks': 'datacentre',
            'NeutronL3HA': False,
            'NeutronNetworkVLANRanges': 'datacentre:1:1000',
            'NeutronPassword': '******',
            'NeutronPublicInterface': 'nic1',
            'NovaImage': 'overcloud-full',
            'NovaPassword': '******',
            'NtpServer': '',
            'OvercloudBlockStorageFlavor': 'baremetal',
            'OvercloudCephStorageFlavor': 'baremetal',
            'OvercloudComputeFlavor': 'baremetal',
            'OvercloudControlFlavor': 'baremetal',
            'OvercloudSwiftStorageFlavor': 'baremetal',
            'SnmpdReadonlyUserPassword': '******',
            'SwiftHashSuffix': 'password',
            'SwiftPassword': '******',
            'SwiftStorageImage': 'overcloud-full',
        }
        self.assertEqual(set(kwargs['parameters'].keys())
                         ^ set(expected_parameters.keys()), set())
        self.assertEqual(kwargs['parameters'], expected_parameters)

        self.assertEqual(kwargs['files'], {})
        self.assertEqual(kwargs['template'], 'template')
        self.assertEqual(kwargs['environment'], 'env')
        self.assertEqual(kwargs['stack_name'], 'overcloud')

        mock_get_templte_contents.assert_called_with(
            ('/usr/share/openstack-tripleo-heat-templates/overcloud-without-'
             'mergepy.yaml'))
    def test_deploy_custom_templates(self, mock_check_hypervisor_stats,
                                     mock_get_key,
                                     mock_create_env, generate_certs_mock,
                                     mock_get_templte_contents,
                                     mock_process_multiple_env,
                                     wait_for_stack_ready_mock,
                                     mock_remove_known_hosts,
                                     mock_keystone_initialize,
                                     mock_sleep, mock_setup_endpoints,
                                     mock_create_overcloudrc,
                                     mock_generate_overcloud_passwords,
                                     mock_update_nodesjson,
                                     mock_deploy_postconfig):

        arglist = ['--templates', '/home/stack/tripleo-heat-templates']
        verifylist = [
            ('templates', '/home/stack/tripleo-heat-templates'),
        ]

        mock_generate_overcloud_passwords.return_value = self._get_passwords()

        clients = self.app.client_manager
        orchestration_client = clients.rdomanager_oscplugin.orchestration()
        mock_stack = fakes.create_to_dict_mock(
            outputs=[{
                'output_key': 'KeystoneURL',
                'output_value': 'Overcloud endpoint'
            }]
        )
        orchestration_client.stacks.get.return_value = mock_stack

        mock_check_hypervisor_stats.return_value = {
            'count': 4,
            'memory_mb': 4096,
            'vcpus': 8,
        }
        mock_get_key.return_value = "PASSWORD"
        clients.network.api.find_attr.return_value = {
            "id": "network id"
        }
        mock_create_env.return_value = "/fake/path"
        mock_process_multiple_env.return_value = [{}, "env"]
        mock_get_templte_contents.return_value = [{}, "template"]
        wait_for_stack_ready_mock.return_value = True

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        self.cmd.take_action(parsed_args)

        args, kwargs = orchestration_client.stacks.update.call_args

        self.assertEqual(args, (orchestration_client.stacks.get().id, ))

        # The parameters output contains lots of output and some is random.
        # So lets just check that it is present
        self.assertTrue('parameters' in kwargs)

        self.assertEqual(kwargs['files'], {})
        self.assertEqual(kwargs['template'], 'template')
        self.assertEqual(kwargs['environment'], 'env')
        self.assertEqual(kwargs['stack_name'], 'overcloud')

        mock_get_templte_contents.assert_called_with(
            '/home/stack/tripleo-heat-templates/overcloud-without-mergepy.yaml'
        )
    def test_tht_scale(self, mock_uuid1, mock_create_cephx_key,
                       mock_check_hypervisor_stats, mock_get_key,
                       mock_create_env, generate_certs_mock,
                       mock_get_templte_contents, mock_process_multiple_env,
                       wait_for_stack_ready_mock, mock_remove_known_hosts,
                       mock_keystone_initialize, mock_sleep,
                       mock_setup_endpoints, mock_create_overcloudrc,
                       mock_generate_overcloud_passwords,
                       mock_update_nodesjson, mock_deploy_postconfig):

        arglist = ['--templates', '--ceph-storage-scale', '3']
        verifylist = [
            ('templates', '/usr/share/openstack-tripleo-heat-templates/'),
        ]

        mock_create_cephx_key.return_value = "cephx_key"
        mock_uuid1.return_value = "uuid"

        mock_generate_overcloud_passwords.return_value = self._get_passwords()

        clients = self.app.client_manager
        orchestration_client = clients.rdomanager_oscplugin.orchestration()
        mock_stack = fakes.create_to_dict_mock(
            outputs=[{
                'output_key': 'KeystoneURL',
                'output_value': 'Overcloud endpoint'
            }])
        orchestration_client.stacks.get.return_value = mock_stack

        mock_check_hypervisor_stats.return_value = {
            'count': 4,
            'memory_mb': 4096,
            'vcpus': 8,
        }
        mock_get_key.return_value = "PASSWORD"
        clients.network.api.find_attr.return_value = {"id": "network id"}
        mock_create_env.return_value = "/fake/path"
        mock_process_multiple_env.return_value = [{}, "env"]
        mock_get_templte_contents.return_value = [{}, "template"]
        wait_for_stack_ready_mock.return_value = True

        parsed_args = self.check_parser(self.cmd, arglist, verifylist)

        self.cmd.take_action(parsed_args)

        args, kwargs = orchestration_client.stacks.update.call_args

        self.assertEqual(args, (orchestration_client.stacks.get().id, ))

        expected_parameters = {
            'AdminPassword': '******',
            'AdminToken': 'password',
            'BlockStorageImage': 'overcloud-full',
            'CeilometerMeteringSecret': 'password',
            'CeilometerPassword': '******',
            'CephStorageCount': 3,
            'CephStorageImage': 'overcloud-full',
            'CinderISCSIHelper': 'lioadm',
            'CinderPassword': '******',
            'CloudName': 'overcloud',
            'controllerImage': 'overcloud-full',
            'Debug': 'True',
            'ExtraConfig': '{}',
            'GlancePassword': '******',
            'HeatPassword': '******',
            'HeatStackDomainAdminPassword': '******',
            'HypervisorNeutronPhysicalBridge': 'br-ex',
            'HypervisorNeutronPublicInterface': 'nic1',
            'NeutronAllowL3AgentFailover': False,
            'NeutronBridgeMappings': 'datacentre:br-ex',
            'NeutronControlPlaneID': 'network id',
            'NeutronDhcpAgentsPerNetwork': 3,
            'NeutronDnsmasqOptions': 'dhcp-option-force=26,1400',
            'NeutronFlatNetworks': 'datacentre',
            'NeutronL3HA': False,
            'NeutronNetworkVLANRanges': 'datacentre:1:1000',
            'NeutronPassword': '******',
            'NeutronPublicInterface': 'nic1',
            'NovaImage': 'overcloud-full',
            'NovaPassword': '******',
            'NtpServer': '',
            'OvercloudBlockStorageFlavor': 'baremetal',
            'OvercloudCephStorageFlavor': 'baremetal',
            'OvercloudComputeFlavor': 'baremetal',
            'OvercloudControlFlavor': 'baremetal',
            'OvercloudSwiftStorageFlavor': 'baremetal',
            'SnmpdReadonlyUserPassword': '******',
            'SwiftHashSuffix': 'password',
            'SwiftPassword': '******',
            'SwiftStorageImage': 'overcloud-full',
        }
        self.assertEqual(
            set(kwargs['parameters'].keys()) ^ set(expected_parameters.keys()),
            set())
        self.assertEqual(kwargs['parameters'], expected_parameters)

        self.assertEqual(kwargs['files'], {})
        self.assertEqual(kwargs['template'], 'template')
        self.assertEqual(kwargs['environment'], 'env')
        self.assertEqual(kwargs['stack_name'], 'overcloud')

        mock_get_templte_contents.assert_called_with(
            ('/usr/share/openstack-tripleo-heat-templates/overcloud-without-'
             'mergepy.yaml'))