Chip Boling | 32aab30 | 2019-01-23 10:50:18 -0600 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2017 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | import structlog |
| 17 | from task import Task |
| 18 | from twisted.internet import reactor |
| 19 | from voltha.protos.voltha_pb2 import ImageDownload |
| 20 | |
| 21 | class OmciSwImageUpgradeTask(Task): |
| 22 | name = "OMCI Software Image Upgrade Task" |
| 23 | |
| 24 | |
| 25 | def __init__(self, img_id, omci_upgrade_sm_cls, omci_agent, image_download, clock=None): |
| 26 | super(OmciSwImageUpgradeTask, self).__init__(OmciSwImageUpgradeTask.name, omci_agent, image_download.id, |
| 27 | exclusive=False, |
| 28 | watchdog_timeout=45) |
| 29 | self.log.debug("OmciSwImageUpgradeTask create ", image_id=img_id) |
| 30 | self._image_id = img_id |
| 31 | self._omci_upgrade_sm_cls = omci_upgrade_sm_cls |
| 32 | # self._omci_agent = omci_agent |
| 33 | self._image_download = image_download |
| 34 | self.reactor = clock if clock is not None else reactor |
| 35 | self._omci_upgrade_sm = None |
| 36 | self.log.debug("OmciSwImageUpgradeTask create end", image_id=img_id) |
| 37 | |
| 38 | @property |
| 39 | def status(self): |
| 40 | return self._image_download |
| 41 | |
| 42 | def start(self): |
| 43 | self.log.debug("OmciSwImageUpgradeTask start") |
| 44 | super(OmciSwImageUpgradeTask, self).start() |
| 45 | if self._omci_upgrade_sm is None: |
| 46 | self._omci_upgrade_sm = self._omci_upgrade_sm_cls(self._image_id, self.omci_agent, self._image_download, clock=self.reactor) |
| 47 | d = self._omci_upgrade_sm.start() |
| 48 | d.chainDeferred(self.deferred) |
| 49 | #else: |
| 50 | # if restart: |
| 51 | # self._omci_upgrade_sm.reset_image() |
| 52 | |
| 53 | def stop(self): |
| 54 | self.log.debug("OmciSwImageUpgradeTask stop") |
| 55 | if self._omci_upgrade_sm is not None: |
| 56 | self._omci_upgrade_sm.stop() |
| 57 | self._omci_upgrade_sm = None |
| 58 | |
| 59 | def onu_bootup(self): |
| 60 | self.log.debug("onu_bootup", state=self._omci_upgrade_sm.status.image_state); |
| 61 | if self._omci_upgrade_sm is not None \ |
| 62 | and self._omci_upgrade_sm.status.image_state == ImageDownload.IMAGE_ACTIVATE: |
| 63 | self._omci_upgrade_sm.do_commit() |
| 64 | |