def test_process_role_param_defaults(self, mock_load, mock_write):
        def move_params_to_param_defaults(d):
            data = dict(d)
            for k, v in data['parameters'].items():
                data['parameter_defaults'][k] = v
            data.pop('parameters', None)
            return data

        pd_base_data = move_params_to_param_defaults(role_base_data)
        pd_specific_data = move_params_to_param_defaults(role_specific_data)
        pd_original_data = move_params_to_param_defaults(role_original_data)
        mock_load.return_value = (pd_base_data, pd_specific_data,
                                  pd_original_data)
        args = mock.Mock()
        args.id = 'foo'
        role_file, role = deploy._process_role('foo-compute.yaml', 'foo.yaml',
                                               'foo', args)
        mock_load.assert_called_once_with('foo.yaml', 'foo-compute.yaml', args)
        self.assertEqual('env-foo-compute.yaml', role_file)
        self.assertEqual('compute', role)
        output = mock_write.call_args[0][0]
        # These values are computed in _process_role
        self.assertEqual('baremetal-foo-compute',
                         output['parameters']['baremetal_prefix'])
        self.assertEqual('bmc-foo-compute', output['parameters']['bmc_prefix'])
 def test_process_role(self, mock_load, mock_write):
     mock_load.return_value = (role_base_data, role_specific_data,
                               role_original_data)
     args = mock.Mock()
     args.id = 'foo'
     role_file, role = deploy._process_role('foo-compute.yaml', 'foo.yaml',
                                            'foo', args)
     mock_load.assert_called_once_with('foo.yaml', 'foo-compute.yaml', args)
     self.assertEqual('env-foo-compute.yaml', role_file)
     self.assertEqual('compute', role)
     output = mock_write.call_args[0][0]
     # These values are computed in _process_role
     self.assertEqual('baremetal-foo-compute',
                      output['parameters']['baremetal_prefix'])
     self.assertEqual('bmc-foo-compute', output['parameters']['bmc_prefix'])
     # These should be inherited
     self.assertEqual('ipxe-boot', output['parameters']['baremetal_image'])
     self.assertEqual('tenant-foo',
                      output['parameter_defaults']['overcloud_tenant_net'])
     # This should not be present in a role env, even if set in the file
     self.assertNotIn('OS::OVB::BaremetalNetworks',
                      output['resource_registry'])
     # This should be the value set in the role env, not the base one
     self.assertEqual(
         'templates/baremetal-ports-all.yaml',
         output['resource_registry']['OS::OVB::BaremetalPorts'])
     # This should be inherited from the base env
     self.assertEqual('templates/bmc-port-port-security.yaml',
                      output['resource_registry']['OS::OVB::BMCPort'])