def testOutputInsnsReplacements(self): """Verify output instructions can be updated""" exp_content = """[insns] channel = dev keyset = batman chromeos_shell = false ensure_no_password = true firmware_update = true security_checks = true create_nplusone = true [general] board = board config_board = test.board """ sect_insns = { 'channel': 'dev', 'keyset': 'batman', } sect_general = { 'config_board': 'test.board', 'board': 'board', } insns = pushimage.InputInsns('test.board') m = self.PatchObject(osutils, 'WriteFile') insns.OutputInsns('/a/file', sect_insns, sect_general) self.assertTrue(m.called) content = m.call_args_list[0][0][1] self.assertEqual(content.rstrip(), exp_content.rstrip())
def testGetInsnFile(self): """Verify various inputs result in right insns path""" testdata = ( ('UPPER_CAPS', 'UPPER_CAPS'), ('recovery', 'test.board'), ('firmware', 'test.board.firmware'), ('factory', 'test.board.factory'), ) insns = pushimage.InputInsns('test.board') for image_type, filename in testdata: ret = insns.GetInsnFile(image_type) self.assertEqual(os.path.basename(ret), '%s.instructions' % (filename))
def testOutputInsnsBasic(self): """Verify output instructions are sane""" exp_content = """[insns] channel = dev canary keyset = stumpy-mp-v3 chromeos_shell = false ensure_no_password = true firmware_update = true security_checks = true create_nplusone = true [general] """ insns = pushimage.InputInsns('test.board') self.assertEqual(insns.GetAltInsnSets(), [None]) m = self.PatchObject(osutils, 'WriteFile') insns.OutputInsns('/bogus', {}, {}) self.assertTrue(m.called) content = m.call_args_list[0][0][1] self.assertEqual(content.rstrip(), exp_content.rstrip())
def testBasic(self): """Simple smoke test""" insns = pushimage.InputInsns('test.board') insns.GetInsnFile('recovery') self.assertEqual(insns.GetChannels(), ['dev', 'canary']) self.assertEqual(insns.GetKeysets(), ['stumpy-mp-v3'])
def testOutputInsnsMergeAlts(self): """Verify handling of alternative insns.xxx sections""" TEMPLATE_CONTENT = """[insns] channel = %(channel)s chromeos_shell = false ensure_no_password = true firmware_update = true security_checks = true create_nplusone = true override = sect_insns keyset = %(keyset)s %(extra)s [general] board = board config_board = test.board """ exp_alts = ['insns.one', 'insns.two', 'insns.hotsoup'] exp_fields = { 'one': { 'channel': 'dev canary', 'keyset': 'OneKeyset', 'extra': '' }, 'two': { 'channel': 'best', 'keyset': 'TwoKeyset', 'extra': '' }, 'hotsoup': { 'channel': 'dev canary', 'keyset': 'ColdKeyset', 'extra': 'soup = cheddar\n', }, } # Make sure this overrides the insn sections. sect_insns = { 'override': 'sect_insns', } sect_insns_copy = sect_insns.copy() sect_general = { 'config_board': 'test.board', 'board': 'board', } insns = pushimage.InputInsns('test.multi') self.assertEqual(insns.GetAltInsnSets(), exp_alts) m = self.PatchObject(osutils, 'WriteFile') for alt in exp_alts: m.reset_mock() insns.OutputInsns('/a/file', sect_insns, sect_general, insns_merge=alt) self.assertEqual(sect_insns, sect_insns_copy) self.assertTrue(m.called) content = m.call_args_list[0][0][1] exp_content = TEMPLATE_CONTENT % exp_fields[alt[6:]] self.assertEqual(content.rstrip(), exp_content.rstrip())