[Notes] [Git][BuildGrid/buildgrid][finn/one-lease-per-worker] 4 commits: Allow user to change time period of bot updates through the cli.



Title: GitLab

finn pushed to branch finn/one-lease-per-worker at BuildGrid / buildgrid

Commits:

5 changed files:

Changes:

  • buildgrid/_app/bots/buildbox.py
    ... ... @@ -46,11 +46,6 @@ def work_buildbox(context, lease):
    46 46
             command = downloader.get_message(action.command_digest,
    
    47 47
                                              remote_execution_pb2.Command())
    
    48 48
     
    
    49
    -    environment = {}
    
    50
    -    for variable in command.environment_variables:
    
    51
    -        if variable.name not in ['PWD']:
    
    52
    -            environment[variable.name] = variable.value
    
    53
    -
    
    54 49
         if command.working_directory:
    
    55 50
             working_directory = command.working_directory
    
    56 51
         else:
    
    ... ... @@ -82,6 +77,12 @@ def work_buildbox(context, lease):
    82 77
                 if context.cas_server_cert:
    
    83 78
                     command_line.append('--server-cert={}'.format(context.cas_server_cert))
    
    84 79
     
    
    80
    +            command_line.append('--clearenv')
    
    81
    +            for variable in command.environment_variables:
    
    82
    +                command_line.append('--setenv')
    
    83
    +                command_line.append(variable.name)
    
    84
    +                command_line.append(variable.value)
    
    85
    +
    
    85 86
                 command_line.append(context.fuse_dir)
    
    86 87
                 command_line.extend(command.arguments)
    
    87 88
     
    

  • buildgrid/_app/commands/cmd_bot.py
    ... ... @@ -52,16 +52,19 @@ from ..cli import pass_context
    52 52
                   help="Public CAS client certificate for TLS (PEM-encoded)")
    
    53 53
     @click.option('--cas-server-cert', type=click.Path(exists=True, dir_okay=False), default=None,
    
    54 54
                   help="Public CAS server certificate for TLS (PEM-encoded)")
    
    55
    +@click.option('--update-period', type=click.FLOAT, default=0.5, show_default=True,
    
    56
    +              help="Time period for bot updates to the server in seconds.")
    
    55 57
     @click.option('--parent', type=click.STRING, default='main', show_default=True,
    
    56 58
                   help="Targeted farm resource.")
    
    57 59
     @pass_context
    
    58
    -def cli(context, parent, remote, client_key, client_cert, server_cert,
    
    60
    +def cli(context, parent, update_period, remote, client_key, client_cert, server_cert,
    
    59 61
             remote_cas, cas_client_key, cas_client_cert, cas_server_cert):
    
    60 62
         # Setup the remote execution server channel:
    
    61 63
         url = urlparse(remote)
    
    62 64
     
    
    63 65
         context.remote = '{}:{}'.format(url.hostname, url.port or 50051)
    
    64 66
         context.remote_url = remote
    
    67
    +    context.update_period = update_period
    
    65 68
         context.parent = parent
    
    66 69
     
    
    67 70
         if url.scheme == 'http':
    
    ... ... @@ -138,7 +141,7 @@ def run_dummy(context):
    138 141
         Creates a session, accepts leases, does fake work and updates the server.
    
    139 142
         """
    
    140 143
         try:
    
    141
    -        b = bot.Bot(context.bot_session)
    
    144
    +        b = bot.Bot(context.bot_session, context.update_period)
    
    142 145
             b.session(dummy.work_dummy,
    
    143 146
                       context)
    
    144 147
         except KeyboardInterrupt:
    
    ... ... @@ -153,7 +156,7 @@ def run_host_tools(context):
    153 156
         result back to CAS.
    
    154 157
         """
    
    155 158
         try:
    
    156
    -        b = bot.Bot(context.bot_session)
    
    159
    +        b = bot.Bot(context.bot_session, context.update_period)
    
    157 160
             b.session(host.work_host_tools,
    
    158 161
                       context)
    
    159 162
         except KeyboardInterrupt:
    
    ... ... @@ -174,7 +177,7 @@ def run_buildbox(context, local_cas, fuse_dir):
    174 177
         context.fuse_dir = fuse_dir
    
    175 178
     
    
    176 179
         try:
    
    177
    -        b = bot.Bot(context.bot_session)
    
    180
    +        b = bot.Bot(context.bot_session, context.update_period)
    
    178 181
             b.session(buildbox.work_buildbox,
    
    179 182
                       context)
    
    180 183
         except KeyboardInterrupt:
    

  • buildgrid/server/bots/instance.py
    ... ... @@ -66,7 +66,9 @@ class BotsInterface:
    66 66
             self._bot_sessions[name] = bot_session
    
    67 67
             self.logger.info("Created bot session name=[{}] with bot_id=[{}]".format(name, bot_id))
    
    68 68
     
    
    69
    -        for lease in self._scheduler.create_leases():
    
    69
    +        # For now, one lease at a time.
    
    70
    +        lease = self._scheduler.create_lease()
    
    71
    +        if lease:
    
    70 72
                 bot_session.leases.extend([lease])
    
    71 73
     
    
    72 74
             return bot_session
    
    ... ... @@ -83,8 +85,11 @@ class BotsInterface:
    83 85
             del bot_session.leases[:]
    
    84 86
             bot_session.leases.extend(leases)
    
    85 87
     
    
    86
    -        for lease in self._scheduler.create_leases():
    
    87
    -            bot_session.leases.extend([lease])
    
    88
    +        # For now, one lease at a time
    
    89
    +        if not bot_session.leases:
    
    90
    +            lease = self._scheduler.create_lease()
    
    91
    +            if lease:
    
    92
    +                bot_session.leases.extend([lease])
    
    88 93
     
    
    89 94
             self._bot_sessions[name] = bot_session
    
    90 95
             return bot_session
    

  • buildgrid/server/scheduler.py
    ... ... @@ -108,10 +108,11 @@ class Scheduler:
    108 108
             if state in (LeaseState.PENDING.value, LeaseState.ACTIVE.value):
    
    109 109
                 self.retry_job(name)
    
    110 110
     
    
    111
    -    def create_leases(self):
    
    112
    -        while self.queue:
    
    111
    +    def create_lease(self):
    
    112
    +        if self.queue:
    
    113 113
                 job = self.queue.popleft()
    
    114 114
                 job.update_execute_stage(ExecuteStage.EXECUTING)
    
    115 115
                 job.create_lease()
    
    116 116
                 job.lease.state = LeaseState.PENDING.value
    
    117
    -            yield job.lease
    117
    +            return job.lease
    
    118
    +        return None

  • tests/integration/bots_service.py
    ... ... @@ -129,7 +129,7 @@ def test_number_of_leases(number_of_jobs, bot_session, context, instance):
    129 129
         request = bots_pb2.CreateBotSessionRequest(bot_session=bot_session)
    
    130 130
         response = instance.CreateBotSession(request, context)
    
    131 131
     
    
    132
    -    assert len(response.leases) == number_of_jobs
    
    132
    +    assert len(response.leases) == min(number_of_jobs, 1)
    
    133 133
     
    
    134 134
     
    
    135 135
     def test_update_leases_with_work(bot_session, context, instance):
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]