Revision 4b61ee63 ci/utils.py

b/ci/utils.py
19 19
from kamaki.clients.cyclades import CycladesClient
20 20
from kamaki.clients.image import ImageClient
21 21
from kamaki.clients.compute import ComputeClient
22
import filelocker
22 23

  
23 24
DEFAULT_CONFIG_FILE = "new_config"
24 25
# UUID of owner of system images
......
147 148
        self.config.read(config_file)
148 149

  
149 150
        # Read temporary_config file
150
        temp_config = self.config.get('Global', 'temporary_config')
151
        self.temp_config_file = \
152
            os.path.expanduser(self.config.get('Global', 'temporary_config'))
151 153
        self.temp_config = ConfigParser()
152 154
        self.temp_config.optionxform = str
153
        self.temp_config.read(os.path.expanduser(temp_config))
155
        self.temp_config.read(self.temp_config_file)
154 156
        self.build_id = build_id
155 157
        self.logger.info("Will use \"%s\" as build id" % _green(self.build_id))
156 158

  
......
453 455

  
454 456
    def write_temp_config(self, option, value):
455 457
        """Write changes back to config file"""
456
        # If build_id section doesn't exist create a new one
457
        try:
458
            self.temp_config.add_section(str(self.build_id))
459
            creation_time = time.strftime("%a, %d %b %Y %X", time.localtime())
460
            self.write_temp_config("created", creation_time)
461
        except DuplicateSectionError:
462
            pass
463
        self.temp_config.set(str(self.build_id), option, str(value))
464
        curr_time = time.strftime("%a, %d %b %Y %X", time.localtime())
465
        self.temp_config.set(str(self.build_id), "modified", curr_time)
466
        temp_conf_file = self.config.get('Global', 'temporary_config')
467
        with open(temp_conf_file, 'wb') as tcf:
468
            self.temp_config.write(tcf)
458
        # Acquire the lock to write to temp_config_file
459
        with filelocker.lock("%s.lock" % self.temp_config_file,
460
                             filelocker.LOCK_EX):
461

  
462
            # Read temp_config again to get any new entries
463
            self.temp_config.read(self.temp_config_file)
464

  
465
            # If build_id section doesn't exist create a new one
466
            try:
467
                self.temp_config.add_section(str(self.build_id))
468
                creation_time = \
469
                    time.strftime("%a, %d %b %Y %X", time.localtime())
470
                self.temp_config.set(str(self.build_id),
471
                                     "created", str(creation_time))
472
            except DuplicateSectionError:
473
                pass
474
            self.temp_config.set(str(self.build_id), option, str(value))
475
            curr_time = time.strftime("%a, %d %b %Y %X", time.localtime())
476
            self.temp_config.set(str(self.build_id), "modified", curr_time)
477
            with open(self.temp_config_file, 'wb') as tcf:
478
                self.temp_config.write(tcf)
469 479

  
470 480
    def read_temp_config(self, option):
471 481
        """Read from temporary_config file"""
......
545 555
            # namely to disable host checking.
546 556
            (temp_ssh_file_handle, temp_ssh_file) = tempfile.mkstemp()
547 557
            os.close(temp_ssh_file_handle)
558
            # XXX: git push doesn't read the password
548 559
            cmd = """
549 560
            echo 'exec ssh -o "StrictHostKeyChecking no" \
550 561
                           -o "UserKnownHostsFile /dev/null" \

Also available in: Unified diff