Guest User

Untitled

a guest
Feb 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. diff --git a/cloudinit/sources/DataSourceSmartOS.py b/cloudinit/sources/DataSourceSmartOS.py
  2. index 32655131..b1676f92 100644
  3. --- a/cloudinit/sources/DataSourceSmartOS.py
  4. +++ b/cloudinit/sources/DataSourceSmartOS.py
  5. @@ -28,6 +29,7 @@ import os
  6. import random
  7. import re
  8. import socket
  9. +import time
  10.  
  11. from cloudinit import log as logging
  12. from cloudinit import serial
  13. @@ -492,7 +494,23 @@ class JoyentMetadataSerialClient(JoyentMetadataClient):
  14. def open_transport(self):
  15. ser = serial.Serial(self.device, timeout=self.timeout)
  16. if not ser.isOpen():
  17. - raise SystemError("Unable to open %s" % self.device)
  18. + # There is some sort of a race between cloud-init and mdata-get
  19. + # that can cause the serial device to not open on the initial
  20. + # attempt.
  21. + for tries in range(1, 11):
  22. + try:
  23. + ser.open()
  24. + assert(ser.isOpen())
  25. + break
  26. + except OSError as exc:
  27. + # This is probably a SerialException, which is a subclass
  28. + # of OSError. SerialException is not used becasue of
  29. + # existing efforts to make pyserial optional.
  30. + LOG.debug("Failed to open %s on try %d: %s", self.device,
  31. + tries, exc)
  32. + time.sleep(0.1)
  33. + else:
  34. + raise SystemError("Unable to open %s" % self.device)
  35. fcntl.lockf(ser, fcntl.LOCK_EX)
  36. self.fp = ser
Add Comment
Please, Sign In to add comment