-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into patch-timeout-1
- Loading branch information
Showing
13 changed files
with
343 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright 2016 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Actions to regenerate Glazier tasklist.""" | ||
|
||
import os | ||
|
||
from glazier.lib import constants | ||
from glazier.lib import flags | ||
from glazier.lib import logs | ||
from glazier.lib import registry | ||
from glazier.lib import winpe | ||
from glazier.lib.actions import base | ||
from glazier.lib.config import builder | ||
|
||
from glazier.lib import buildinfo | ||
|
||
|
||
logging = logs.logging | ||
|
||
|
||
class RegenerateTasklist(base.BaseAction): | ||
"""Regenerate Glazier tasklist.""" | ||
|
||
def __init__(self): | ||
self._build_info = buildinfo.BuildInfo() | ||
|
||
def _PurgeTaskList(self): | ||
"""Determines the location of the task list and erases it for regeneration.""" | ||
location = constants.SYS_TASK_LIST | ||
if winpe.check_winpe(): | ||
location = constants.WINPE_TASK_LIST | ||
logging.info('Using task list at %s', location) | ||
if os.path.exists(location): | ||
logging.info('Purging old task list.') | ||
try: | ||
os.remove(location) | ||
except OSError as e: | ||
raise base.ActionError() from e | ||
return location | ||
|
||
def Run(self): | ||
regen_run = registry.get_value('tasklist_regen', path=constants.REG_ROOT) | ||
if regen_run != 'True': | ||
task_list = self._PurgeTaskList() | ||
root_path = flags.CONFIG_ROOT_PATH.value or '/' | ||
try: | ||
b = builder.ConfigBuilder(self._build_info) | ||
b.Start(out_file=task_list, in_path=root_path) | ||
except builder.ConfigBuilderError as e: | ||
raise base.ActionError() from e | ||
registry.set_value('tasklist_regen', 'True', path=constants.REG_ROOT) | ||
|
||
def Validate(self): | ||
self._ListOfStringsValidator(self._args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2016 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Tests for glazier.lib.actions.tasklist.""" | ||
|
||
from unittest import mock | ||
|
||
from absl.testing import absltest | ||
from glazier.lib import test_utils | ||
from glazier.lib import winpe | ||
from glazier.lib.actions import base | ||
from glazier.lib.actions import tasklist | ||
|
||
|
||
class TasklistTest(test_utils.GlazierTestCase): | ||
|
||
@mock.patch.object(tasklist, 'logs', autospec=True) | ||
def setUp(self, logs): | ||
super().setUp() | ||
self.tasklist = tasklist.RegenerateTasklist() | ||
tasklist.logging = logs.logging | ||
|
||
@mock.patch.object(winpe, 'check_winpe', autospec=True) | ||
def test_setup_task_list_host(self, mock_check_winpe): | ||
tasklist_location = tasklist.constants.SYS_TASK_LIST | ||
mock_check_winpe.return_value = False | ||
self.assertEqual(self.tasklist._PurgeTaskList(), tasklist_location) | ||
|
||
@mock.patch.object(winpe, 'check_winpe', autospec=True) | ||
def test_setup_task_list_winpe(self, mock_check_winpe): | ||
self.patch_constant_file_path(tasklist.constants, 'WINPE_TASK_LIST') | ||
mock_check_winpe.return_value = True | ||
tasklist_location = tasklist.constants.WINPE_TASK_LIST | ||
self.assertEqual(self.tasklist._PurgeTaskList(), tasklist_location) | ||
|
||
@mock.patch.object(tasklist, 'os', autospec=True) | ||
def test_setup_task_list_error(self, mock_os): | ||
self.patch_constant_file_path(tasklist.constants, 'SYS_TASK_LIST') | ||
mock_os.remove.side_effect = OSError | ||
with self.assertRaises(base.ActionError): | ||
self.tasklist._PurgeTaskList() | ||
|
||
|
||
if __name__ == '__main__': | ||
absltest.main() |
Oops, something went wrong.