def test_bootstrap_command_linux_stable(self, tempdir, get_params, isfile):
    gce.Authenticator.is_gce.return_value = True
    recipe_cmd = ['run_recipe.py', 'recipe_params...']

    tempdir.return_value = 'foo'
    get_params.return_value = ldbs.Params(
        project='myproject', cipd_tag='stable', api=self.stable_api,
        mastername='mastername', buildername='buildername', buildnumber=1337,
        logdog_only=False, generation=None)
    isfile.return_value = True

    streamserver_uri = 'unix:%s' % (os.path.join('foo', 'butler.sock'),)

    bs = ldbs.bootstrap(self.rt, self.opts, self.basedir, self.tdir,
                        self.properties, recipe_cmd)

    # Check CIPD installation.
    cipd_dir = os.path.join(self.basedir, '.recipe_cipd')
    cipd_bootstrap_v2.install_cipd_packages.assert_called_once_with(
        cipd_dir,
        cipd.CipdPackage(
            name='infra/tools/luci/logdog/butler/${platform}',
            version='stable'),
        cipd.CipdPackage(
            name='infra/tools/luci/logdog/annotee/${platform}',
            version='stable'),
    )

    # Check bootstrap command.
    self.assertEqual(
        bs.cmd,
        [os.path.join(cipd_dir, 'logdog_butler'),
            '-log-level', 'warning',
            '-project', 'myproject',
            '-prefix', 'bb/mastername/buildername/1337',
            '-coordinator-host', 'luci-logdog.appspot.com',
            '-output', 'logdog',
            '-tag', 'buildbot.master=mastername',
            '-tag', 'buildbot.builder=buildername',
            '-tag', 'buildbot.buildnumber=1337',
            '-tag', 'logdog.viewer_url=https://luci-milo.appspot.com/buildbot/'
                    'mastername/buildername/1337',
            '-service-account-json', ':gce',
            '-output-max-buffer-age', '30s',
            'run',
            '-stdout', 'tee=stdout',
            '-stderr', 'tee=stderr',
            '-streamserver-uri', streamserver_uri,
            '--',
            os.path.join(cipd_dir, 'logdog_annotee'),
                '-log-level', 'warning',
                '-name-base', 'recipes',
                '-print-summary',
                '-tee', 'annotations,text',
                '-json-args-path', self._tp('logdog_annotee_cmd.json'),
                '-result-path', self._tp('bootstrap_result.json'),
        ])

    self._assertAnnoteeCommand(recipe_cmd)
  def setUp(self):
    logging.basicConfig(level=logging.ERROR+1)
    self.maxDiff = None

    self._patchers = []
    map(self._patch, (
        mock.patch('slave.infra_platform.get'),
        mock.patch('slave.logdog_bootstrap._check_call'),
        mock.patch('slave.gce.Authenticator.is_gce'),
        mock.patch('slave.cipd_bootstrap_v2.install_cipd_packages'),
        mock.patch('os.environ', {}),
        ))

    self.rt = robust_tempdir.RobustTempdir(prefix='logdog_bootstrap_test')
    self.basedir = self.rt.tempdir()
    self.tdir = self.rt.tempdir()
    self.opts = MockOptions(
        logdog_verbose=False,
        logdog_disable=False,
        logdog_butler_path=None,
        logdog_annotee_path=None,
        logdog_service_account_json=None,
        logdog_host=None,
        logdog_only=None,
        logdog_debug_out_file=None)
    self.properties = {
      'mastername': 'default',
      'buildername': 'builder',
      'buildnumber': 24601,
    }

    # Stable (default) API.
    self.stable_api = ldbs._CIPD_TAG_API_MAP[ldbs._STABLE_CIPD_TAG]
    self.latest_api = ldbs._CIPD_TAG_API_MAP[ldbs._CANARY_CIPD_TAG]

    # Set of default base params.
    self.base = ldbs.Params(
        project='alpha', cipd_tag=ldbs._STABLE_CIPD_TAG, api=self.stable_api,
        mastername='default', buildername='builder', buildnumber=24601,
        logdog_only=False, generation=None)

    # Control whether we think we're a GCE instnace.
    gce.Authenticator.is_gce.return_value = False

    # Pretend we're 64-bit Linux by default.
    infra_platform.get.return_value = ('linux', 'x86_64', 64)
  def test_bootstrap_command_win_canary(self, tempdir, get_params,
                                        service_account, isfile):
    infra_platform.get.return_value = ('win', 'x86_64', 64)

    recipe_cmd = ['run_recipe.py', 'recipe_params...']

    tempdir.return_value = 'foo'
    get_params.return_value = ldbs.Params(
        project='myproject', cipd_tag='canary',
        api=self.latest_api, mastername='mastername',
        buildername='buildername', buildnumber=1337, logdog_only=True,
        generation=None)
    service_account.return_value = 'creds.json'
    isfile.return_value = True

    bs = ldbs.bootstrap(self.rt, self.opts, self.basedir, self.tdir,
                        self.properties, recipe_cmd)

    # Check CIPD installation.
    cipd_dir = os.path.join(self.basedir, '.recipe_cipd')
    cipd_bootstrap_v2.install_cipd_packages.assert_called_once_with(
        cipd_dir,
        cipd.CipdPackage(
            name='infra/tools/luci/logdog/butler/${platform}',
            version='canary'),
        cipd.CipdPackage(
            name='infra/tools/luci/logdog/annotee/${platform}',
            version='canary'),
    )

    # Check bootstrap command.
    self.assertEqual(
        bs.cmd,
        [os.path.join(cipd_dir, 'logdog_butler.exe'),
            '-log-level', 'warning',
            '-project', 'myproject',
            '-prefix', 'bb/mastername/buildername/1337',
            '-coordinator-host', 'luci-logdog.appspot.com',
            '-output', 'logdog',
            '-tag', 'buildbot.master=mastername',
            '-tag', 'buildbot.builder=buildername',
            '-tag', 'buildbot.buildnumber=1337',
            '-tag', 'logdog.viewer_url=https://luci-milo.appspot.com/buildbot/'
                    'mastername/buildername/1337',
            '-service-account-json', 'creds.json',
            '-output-max-buffer-age', '30s',
            '-io-keepalive-stderr', '5m',
            'run',
            '-stdout', 'tee=stdout',
            '-stderr', 'tee=stderr',
            '-streamserver-uri', 'net.pipe:LUCILogDogButler',
            '--',
            os.path.join(cipd_dir, 'logdog_annotee.exe'),
                '-log-level', 'warning',
                '-name-base', 'recipes',
                '-print-summary',
                '-tee', 'annotations',
                '-json-args-path', self._tp('logdog_annotee_cmd.json'),
                '-result-path', self._tp('bootstrap_result.json'),
        ])

    service_account.assert_called_once_with(
        self.opts, ldbs._PLATFORM_CONFIG[('win',)]['credential_path'])
    self._assertAnnoteeCommand(recipe_cmd)
Esempio n. 4
0
    def test_get_params(self, load_params_dict):
        load_params_dict.return_value = {
            'alpha': {
                'default': {},
                'blacklist': {
                    'blacklisted': {
                        'enabled': False
                    },
                },
                'whitelist': {
                    'whitelisted': {},
                    '*': {
                        'enabled': False
                    },
                },
                'canary': {
                    '*': {
                        'cipd_tag': 'canary'
                    },
                },
            },
        }

        base = ldbs.Params(project='alpha',
                           cipd_tag=ldbs._STABLE_CIPD_TAG,
                           mastername='default',
                           buildername='builder',
                           buildnumber=24601)

        def mp(params):
            props = self.properties.copy()
            props.update({
                'mastername': params.mastername,
                'buildername': params.buildername,
                'buildnumber': params.buildnumber,
            })
            return props

        # No mastername, buildername, and buildnumber returns None.
        with self.assertRaises(ldbs.NotBootstrapped):
            ldbs._get_params(mp(base._replace(mastername=None)))
        with self.assertRaises(ldbs.NotBootstrapped):
            ldbs._get_params(mp(base._replace(buildername=None)))
        with self.assertRaises(ldbs.NotBootstrapped):
            ldbs._get_params(mp(base._replace(buildnumber=None)))

        # Default.
        params = base
        self.assertEqual(ldbs._get_params(mp(params)), params)

        # Blacklist.
        params = base._replace(mastername='blacklist',
                               buildername='blacklisted')
        with self.assertRaises(ldbs.NotBootstrapped):
            ldbs._get_params(mp(params))

        params = base._replace(mastername='blacklist', buildername='other')
        self.assertEqual(ldbs._get_params(mp(params)), params)

        # Whitelist.
        params = base._replace(mastername='whitelist',
                               buildername='whitelisted')
        self.assertEqual(ldbs._get_params(mp(params)), params)

        params = base._replace(mastername='whitelist', buildername='other')
        with self.assertRaises(ldbs.NotBootstrapped):
            ldbs._get_params(mp(params))

        # Canary.
        params = base._replace(mastername='canary', cipd_tag='canary')
        self.assertEqual(ldbs._get_params(mp(params)), params)
Esempio n. 5
0
    def test_bootstrap_command_windows(self, tempdir, get_params,
                                       service_account, install_cipd, isfile):
        infra_platform.get.return_value = ('win', 64)

        recipe_cmd = ['run_recipe.py', 'recipe_params...']

        tempdir.return_value = 'foo'
        get_params.return_value = ldbs.Params(project='myproject',
                                              cipd_tag='stable',
                                              mastername='mastername',
                                              buildername='buildername',
                                              buildnumber=1337)
        install_cipd.return_value = ('logdog_butler.exe', 'logdog_annotee.exe')
        service_account.return_value = 'creds.json'
        isfile.return_value = True

        streamserver_uri = 'net.pipe:LUCILogDogButler'

        bs = ldbs.bootstrap(self.rt, self.opts, self.basedir, self.tdir,
                            self.properties, recipe_cmd)
        self.assertEqual(bs.cmd, [
            'logdog_butler.exe',
            '-log-level',
            'warning',
            '-project',
            'myproject',
            '-prefix',
            'bb/mastername/buildername/1337',
            '-output',
            'logdog,host="services-dot-luci-logdog.appspot.com"',
            '-service-account-json',
            'creds.json',
            '-output-max-buffer-age',
            '30s',
            'run',
            '-stdout',
            'tee=stdout',
            '-stderr',
            'tee=stderr',
            '-streamserver-uri',
            streamserver_uri,
            '--',
            'logdog_annotee.exe',
            '-log-level',
            'warning',
            '-project',
            'myproject',
            '-butler-stream-server',
            streamserver_uri,
            '-logdog-host',
            'luci-logdog.appspot.com',
            '-annotate',
            'tee',
            '-name-base',
            'recipes',
            '-print-summary',
            '-tee',
            '-json-args-path',
            self._tp('logdog_annotee_cmd.json'),
            '-result-path',
            self._tp('bootstrap_result.json'),
        ])

        service_account.assert_called_once_with(
            self.opts, ldbs._PLATFORM_CONFIG[('win', )]['credential_path'])
        self._assertAnnoteeCommand(recipe_cmd)