Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket2624 file tracking #139

Merged
merged 28 commits into from
Oct 19, 2017
Merged

Ticket2624 file tracking #139

merged 28 commits into from
Oct 19, 2017

Conversation

ThomasLohnert
Copy link
Contributor

@ThomasLohnert ThomasLohnert commented Oct 10, 2017

Description of work

Simplified the system responsible for keeping user scripts and configurations under version control:
VC is now managed by a thread running in the blockserver, which simply adds, commits and pushes all files in the repositories every 5 minutes. This change greatly reduces the complexity of the system, removes the need for any filewatchers, and with it previously problematic interactions between the filewatcher and the version control threads.

To test

ISISComputingGroup/IBEX#2624

Acceptance criteria

  • Any changes on the file system are committed to git in regular intervals (currently 5 minutes - you can tweak this interval in the PUSH_BASE_INTERVAL variable in git_version_control.py if it makes testing easier
  • The commit messages provide an appropriate summary of changes
  • Graceful handling of problematic file system / git interactions: Trying to save a file while it is being added; trying to add a file while it is being saved. You can use the following powershell script to manually lock/unlock a file for testing:
  • Interactions with configurations from the GUI are unchanged
#Specify the file name
$fileName = "[file path]"

#Open the file in read only mode, without sharing (I.e., locked as requested)
$file = [System.io.File]::Open($fileName, 'Open', 'Read', 'None')

#Wait in the above (file locked) state until the user presses a key
Write-Host "Press any key to continue ..."
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

#Close the file (This releases the current handle and unlocks the file)
$file.Close()

Code Review

  • Is the code of an acceptable quality?
  • Has the author taken into account the multi-threaded nature of the code?
  • Have the changes been documented in the release notes. If so, do they describe the changes appropriately?
  • Has the manual system tests spreadsheet been updated?

Functional Tests

  • Do changes function as described? Add comments below that describe the tests performed.

Final steps

  • Reviewer has updated the submodule in the main EPICS repo? See Reviewing work for the subModules of EPICS in the Git workflow page for details.
  • Reviewer has moved the release notes entry for this ticket in the "Changes merged into master" section

Copy link
Contributor

@Tom-Willemsen Tom-Willemsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting the following exception, using latest build of genie_python installed from \\isis\inst$\Kits$\CompGroup\ICP\genie_python. Do you perhaps have a different version of Python installed on your system (or, more precisely, GitPython version)? The git python version on the latest build on the build server is 0.3.6

...
INFO: Stopping IOC INHIBITR_01
Alarm server will update in 20 seconds from now

INFO: Stopping IOC CHIPIR_XYZ
Alarm server will update in 20 seconds from now

INFO: Stopping IOC GALIL_02
Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Instrument\Apps\Python\lib\threading.py", line 810, in __bootstrap_inner
    self.run()
  File "C:\Instrument\Apps\Python\lib\threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:\Instrument\Apps\EPICS\ISIS\inst_servers\master\ConfigVersionControl\git_version_control.py", line 152, in _commit_and_push
    self._commit()
  File "C:\Instrument\Apps\EPICS\ISIS\inst_servers\master\ConfigVersionControl\git_version_control.py", line 141, in _commit
    raise CommitToVersionControlException("Couldn't commit to version control")
CommitToVersionControlException: Couldn't commit to version control

Alarm server will update in 20 seconds from now

INFO: Stopping IOC SDTEST_01
Alarm server will update in 20 seconds from now

INFO: Stopping IOC TEST_01
Alarm server will update in 20 seconds from now
...

Code looks good, some small stylistic changes suggested in the review comments, but haven't been able to run this to test it properly.

time.sleep(RETRY_INTERVAL)

raise Exception(
"Could not save to device screens file at %s. Please check the file is not in use by another process." % file_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our standard (from the python style gui chat) is now to use .format() rather than % to format strings

Comment repeats as necessary

attempts += 1
time.sleep(RETRY_INTERVAL)

raise Exception(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't raise Exception, raise a specific exception instead.

attempts += 1
time.sleep(RETRY_INTERVAL)

raise Exception(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't raise Exception

attempts += 1
time.sleep(RETRY_INTERVAL)

raise Exception(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't raise Exception

attempts += 1
time.sleep(RETRY_INTERVAL)

raise Exception(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if you can factor out this block - I've seen a very similar block 4 times so far. You might need to pass in a function to deal with the different bits but the basic

while attempts < RETRY_MAX_ATTEMPTS:
           try:
               with open(file_path, mode) as f:
                   # do something clever
           except IOError:
               attempts += 1
               time.sleep(RETRY_INTERVAL)

#raise something clever

structure should be encapsulated somewhere

block_server.py Outdated
# Start file watcher
self._filewatcher = ConfigFileWatcherManager(SCHEMA_DIR, self._config_list, self._syn, self._devices)
# self._other_files = UnclassifiedFileManager(self) TODO
# self.on_the_fly_handlers.append(self._other_files)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code or complete TODO item.

return
except Exception as err:
except Exception:
sleep(RETRY_INTERVAL)

attempts += 1

raise CommitToVersionControlException("Couldn't commit to version control")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this exception never gets caught.

push_interval = PUSH_BASE_INTERVAL
first_failure = True

except GitCommandError as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to catch CommitToVersionControlException.

@@ -15,19 +15,18 @@
# http://opensource.org/licenses/eclipse-1.0.php

import os
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import appears to be unused

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not, I'm using os.path in a few places here. Not sure why it gets highlighted, I have seen a few people asking the same question online but have not come across a satisfying answer so far

push_interval = PUSH_RETRY_INTERVAL
if first_failure:
print_and_log("Unable to push config changes, will retry in %i seconds"
% PUSH_RETRY_INTERVAL, "MINOR")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use .format() to format strings

@Tom-Willemsen
Copy link
Contributor

  • Tested adding index.lock in my .git directory so that it couldn't commit:q - it retried and committed with an appropriate message once I released the lock.

Code looks good, functionally works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants