"Fossies" - the Fresh Open Source Software Archive

Member "buildbot-2.3.1/buildbot/test/fake/docker.py" (23 May 2019, 3502 Bytes) of package /linux/misc/buildbot-2.3.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "docker.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.0.1_vs_2.1.0.

    1 # This file is part of Buildbot.  Buildbot is free software: you can
    2 # redistribute it and/or modify it under the terms of the GNU General Public
    3 # License as published by the Free Software Foundation, version 2.
    4 #
    5 # This program is distributed in the hope that it will be useful, but WITHOUT
    6 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    7 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    8 # details.
    9 #
   10 # You should have received a copy of the GNU General Public License along with
   11 # this program; if not, write to the Free Software Foundation, Inc., 51
   12 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   13 #
   14 # Copyright Buildbot Team Members
   15 
   16 
   17 version = "1.10.6"
   18 
   19 
   20 class Client:
   21     latest = None
   22 
   23     def __init__(self, base_url):
   24         Client.latest = self
   25         self.call_args_create_container = []
   26         self.call_args_create_host_config = []
   27         self.called_class_name = None
   28         self._images = [
   29             {'RepoTags': ['busybox:latest', 'worker:latest', 'tester:latest']}]
   30         self._pullable = ['alpine:latest', 'tester:latest']
   31         self._pullCount = 0
   32         self._containers = {}
   33 
   34     def images(self):
   35         return self._images
   36 
   37     def start(self, container):
   38         pass
   39 
   40     def stop(self, id):
   41         pass
   42 
   43     def wait(self, id):
   44         return 0
   45 
   46     def build(self, fileobj, tag):
   47         if fileobj.read() == b'BUG':
   48             pass
   49         else:
   50             logs = []
   51             for line in logs:
   52                 yield line
   53             self._images.append({'RepoTags': [tag + ':latest']})
   54 
   55     def pull(self, image, *args, **kwargs):
   56         if image in self._pullable:
   57             self._pullCount += 1
   58             self._images.append({'RepoTags': [image]})
   59 
   60     def containers(self, filters=None, *args, **kwargs):
   61         if filters is not None:
   62             if 'existing' in filters.get('name', ''):
   63                 self.create_container(
   64                     image='busybox:latest',
   65                     name="buildbot-existing-87de7e"
   66                 )
   67                 self.create_container(
   68                     image='busybox:latest',
   69                     name="buildbot-existing-87de7ef"
   70                 )
   71 
   72             return [
   73                 c for c in self._containers.values()
   74                 if c['name'].startswith(filters['name'])
   75             ]
   76         return self._containers.values()
   77 
   78     def create_host_config(self, *args, **kwargs):
   79         self.call_args_create_host_config.append(kwargs)
   80 
   81     def create_container(self, image, *args, **kwargs):
   82         self.call_args_create_container.append(kwargs)
   83         self.called_class_name = self.__class__.__name__
   84         name = kwargs.get('name', None)
   85         if 'buggy' in image:
   86             raise Exception('we could not create this container')
   87         for c in self._containers.values():
   88             if c['name'] == name:
   89                 raise Exception('cannot create with same name')
   90         ret = {
   91             'Id':
   92             '8a61192da2b3bb2d922875585e29b74ec0dc4e0117fcbf84c962204e97564cd7',
   93             'Warnings': None
   94         }
   95         self._containers[ret['Id']] = {
   96             'started': False,
   97             'image': image,
   98             'Id': ret['Id'],
   99             'name': name,  # docker does not return this
  100             'Names': [name]  # this what docker returns
  101         }
  102         return ret
  103 
  104     def remove_container(self, id, **kwargs):
  105         del self._containers[id]
  106 
  107 
  108 class APIClient(Client):
  109     pass