示例#1
0
    def test_chef_berkshelf_default_berksfile(self, mock_isfile,
                                              mock_subproc_popen):
        """It tests Berkshelf usage if no Berksfile path is provided"""
        mock_isfile.return_value = True

        process_mock = mock.Mock()
        attrs = {
            'communicate.return_value': ('output', 'ok'),
            'poll.return_value': 0
        }
        process_mock.configure_mock(**attrs)
        mock_subproc_popen.return_value = process_mock

        template = self.useFixture(ep.ExPlanBerkshelf()).execution_plan
        self.chef_executor.load('path',
                                template['Scripts'].values()[0]['Options'])
        self.chef_executor.module_name = 'test'
        cookbook_path = self.chef_executor._create_cookbook_path('cookbook')

        self.assertEqual(cookbook_path,
                         os.path.abspath('path/berks-cookbooks'))
        expected_command = 'berks vendor --berksfile={0} {1}'.format(
            os.path.abspath('path/cookbook/Berksfile'), cookbook_path)
        mock_subproc_popen.assert_called_once_with(expected_command,
                                                   cwd=ANY,
                                                   shell=ANY,
                                                   stdout=ANY,
                                                   stderr=ANY,
                                                   universal_newlines=ANY)
示例#2
0
    def test_chef_berkshelf_error(self, mock_isfile, mock_subproc_popen):
        """It tests if Berkshelf throws an error"""
        mock_isfile.return_value = True

        process_mock = mock.Mock()
        attrs = {
            'communicate.return_value': ('output', 'error'),
            'poll.return_value': 2
        }
        process_mock.configure_mock(**attrs)
        mock_subproc_popen.return_value = process_mock

        template = self.useFixture(ep.ExPlanBerkshelf()).execution_plan
        self.chef_executor.load('path',
                                template['Scripts'].values()[0]['Options'])
        self.chef_executor.module_name = 'test'
        self.assertRaises(ex.CustomException,
                          self.chef_executor._create_cookbook_path, 'cookbook')
示例#3
0
 def test_verify_execution_plan_berkshelf(self):
     template = self.useFixture(ep.ExPlanBerkshelf()).execution_plan
     self.agent._verify_plan(template)