Example #1
0
    def test_start_worker(self):
        # http://mesosphere.github.io/marathon/docs/rest-api.html#post-v2-apps
        worker = yield self.makeWorker()
        worker.password = "******"
        worker.masterFQDN = "master"
        self._http.expect(
            method='delete',
            ep='/v2/apps/buildbot-worker/buildbot-bot-masterhash')
        self._http.expect(method='post',
                          ep='/v2/apps',
                          json={
                              'instances': 1,
                              'container': {
                                  'docker': {
                                      'image': 'rendered:debian:wheezy',
                                      'network': 'BRIDGE'
                                  },
                                  'type': 'DOCKER'
                              },
                              'id': 'buildbot-worker/buildbot-bot-masterhash',
                              'env': {
                                  'BUILDMASTER': "master",
                                  'BUILDMASTER_PORT': '1234',
                                  'WORKERNAME': 'bot',
                                  'WORKERPASS': "******"
                              }
                          },
                          code=201,
                          content_json={'Id': 'id'})
        d = worker.substantiate(None, fakebuild.FakeBuildForRendering())
        # we simulate a connection
        worker.attached(FakeBot())
        yield d

        self.assertEqual(worker.instance, {'Id': 'id'})
Example #2
0
 def test_start_worker(self):
     worker = yield self.setupWorker('worker')
     d = worker.substantiate(None, FakeBuild())
     worker.attached(FakeBot())
     yield d
     self.assertEqual(len(worker._kube.pods), 1)
     pod_name = list(worker._kube.pods.keys())[0]
     self.assertRegex(pod_name, r'default/buildbot-worker-[0-9a-f]+')
     pod = worker._kube.pods[pod_name]
     self.assertEqual(sorted(pod['spec'].keys()),
                      ['containers', 'restartPolicy'])
     self.assertEqual(sorted(pod['spec']['containers'][0].keys()),
                      ['env', 'image', 'name', 'resources'])
     self.assertEqual(pod['spec']['containers'][0]['image'],
                      'rendered:buildbot/buildbot-worker')
     self.assertEqual(pod['spec']['restartPolicy'], 'Never')
Example #3
0
 def test_start_worker(self):
     worker = yield self.setupWorker('worker', image='test-image')
     # resolve image to storage uuid
     self._http.expect(method='get',
                       ep='/storage/template',
                       content_json=upcloudStorageTemplatePayload)
     # actually start server
     self._http.expect(
         method='post',
         ep='/server',
         params=None,
         data=None,
         json={
             'server': {
                 'zone': 'de-fra1',
                 'title': 'buildbot-worker-87de7e',
                 'hostname': 'worker',
                 'user_data': '',
                 'login_user': {
                     'username': '******',
                     'ssh_keys': {
                         'ssh_key': []
                     }
                 },
                 'password_delivery': 'none',
                 'storage_devices': {
                     'storage_device': [{
                         'action':
                         'clone',
                         'storage':
                         '8b47d21b-b4c3-445d-b75c-5a723ff39681',
                         'title':
                         'buildbot-worker-{}'.format(self.masterhash),
                         'size':
                         10,
                         'tier':
                         'maxiops'
                     }]
                 },
                 'plan': '1xCPU-1GB'
             }
         },
         content_json=upcloudServerCreatePayload,
         code=202)
     # determine it's up & running
     self._http.expect(method='get',
                       ep='/server/438b5b08-4147-4193-bf64-a5318f51d3bd',
                       content_json=upcloudServerStartedPayload)
     # get root password
     self._http.expect(method='get',
                       ep='/server/438b5b08-4147-4193-bf64-a5318f51d3bd',
                       content_json=upcloudServerStartedPayload)
     # stop server
     self._http.expect(
         method='post',
         ep='/server/438b5b08-4147-4193-bf64-a5318f51d3bd/stop',
         json={'stop_server': {
             'stop_type': 'hard',
             'timeout': '1'
         }},
         content_json=upcloudServerStartedPayload)
     # now it's stopped
     self._http.expect(method='get',
                       ep='/server/438b5b08-4147-4193-bf64-a5318f51d3bd',
                       content_json=upcloudServerStoppedPayload)
     # then delete it
     self._http.expect(
         method='delete',
         ep='/server/438b5b08-4147-4193-bf64-a5318f51d3bd?storages=1',
         code=204)
     d = worker.substantiate(None, FakeBuild())
     yield worker.attached(FakeBot())
     yield d