def test_cmp_strict(self): versions = ( ("1.5.1", "1.5.2b2", -1), ("161", "3.10a", ValueError), ("8.02", "8.02", 0), ("3.4j", "1996.07.12", ValueError), ("3.2.pl0", "3.1.1.6", ValueError), ("2g6", "11g", ValueError), ("0.9", "2.2", -1), ("1.2.1", "1.2", 1), ("1.1", "1.2.2", -1), ("1.2", "1.1", 1), ("1.2.1", "1.2.2", -1), ("1.2.2", "1.2", 1), ("1.2", "1.2.2", -1), ("0.4.0", "0.4", 0), ("1.13++", "5.5.kw", ValueError), # Added by us ("1.1.1a1", "1.1.1", -1), ) for v1, v2, wanted in versions: try: res = getattr(StrictVersion(v1), cmp_method)(StrictVersion(v2)) except ValueError: if wanted is ValueError: continue else: raise AssertionError( ("cmp(%s, %s) " "shouldn't raise ValueError") % (v1, v2)) self.assertEqual( res, wanted, "cmp(%s, %s) should be %s, got %s" % (v1, v2, wanted, res))
def test_cmp_strict(self): versions = ( ('1.5.1', '1.5.2b2', -1), ('161', '3.10a', ValueError), ('8.02', '8.02', 0), ('3.4j', '1996.07.12', ValueError), ('3.2.pl0', '3.1.1.6', ValueError), ('2g6', '11g', ValueError), ('0.9', '2.2', -1), ('1.2.1', '1.2', 1), ('1.1', '1.2.2', -1), ('1.2', '1.1', 1), ('1.2.1', '1.2.2', -1), ('1.2.2', '1.2', 1), ('1.2', '1.2.2', -1), ('0.4.0', '0.4', 0), ('1.13++', '5.5.kw', ValueError), # Added by us ('1.1.1a1', '1.1.1', -1)) for v1, v2, wanted in versions: try: res = getattr(StrictVersion(v1), cmp_method)(StrictVersion(v2)) except ValueError: if wanted is ValueError: continue else: raise AssertionError( ("cmp(%s, %s) " "shouldn't raise ValueError") % (v1, v2)) self.assertEqual( res, wanted, 'cmp(%s, %s) should be %s, got %s' % (v1, v2, wanted, res))
def test_prerelease(self): version = StrictVersion("1.2.3a1") self.assertEqual(version.version, (1, 2, 3)) self.assertEqual(version.prerelease, ("a", 1)) self.assertEqual(str(version), "1.2.3a1") version = StrictVersion("1.2.0") self.assertEqual(str(version), "1.2")
def test_prerelease(self): version = StrictVersion('1.2.3a1') self.assertEqual(version.version, (1, 2, 3)) self.assertEqual(version.prerelease, ('a', 1)) self.assertEqual(six.text_type(version), '1.2.3a1') version = StrictVersion('1.2.0') self.assertEqual(six.text_type(version), '1.2')
def test_prerelease(): version = StrictVersion("1.2.3a1") assert version.version == (1, 2, 3) assert version.prerelease == ("a", 1) assert str(version) == "1.2.3a1" version = StrictVersion("1.2.0") assert str(version) == "1.2"
def test_cmp_strict(v1, v2, wanted): try: res = StrictVersion(v1)._cmp(StrictVersion(v2)) assert res == wanted, "cmp({}, {}) should be {}, got {}".format( v1, v2, wanted, res) except ValueError: if wanted is not ValueError: raise AssertionError( "cmp({}, {}) shouldn't raise ValueError".format(v1, v2))
def ec2_tags(): boto_version = StrictVersion(boto.__version__) required_boto_version = StrictVersion('2.8.0') if boto_version < required_boto_version: log.error("Installed boto version %s < %s, can't find ec2_tags", boto_version, required_boto_version) return None if not _on_ec2(): log.info("Not an EC2 instance, skipping") return None instance_id, region = _get_instance_info() credentials = _get_credentials() # Connect to EC2 and parse the Roles tags for this instance try: conn = boto.ec2.connect_to_region( region, aws_access_key_id=credentials['access_key'], aws_secret_access_key=credentials['secret_key'], ) except Exception as e: log.error("Could not get AWS connection: %s", e) return None ec2_tags = {} try: tags = conn.get_all_tags(filters={ 'resource-type': 'instance', 'resource-id': instance_id }) for tag in tags: ec2_tags[tag.name] = tag.value except Exception as e: log.error("Couldn't retrieve instance tags: %s", e) return None ret = dict(ec2_tags=ec2_tags) # Provide ec2_tags_roles functionality if 'Roles' in ec2_tags: ret['ec2_roles'] = ec2_tags['Roles'].split(',') return ret
class _SaltnadoIntegrationTestCase(SaltnadoTestCase): # pylint: disable=abstract-method @property def opts(self): return self.get_config('client_config', from_scratch=True) @property def mod_opts(self): return self.get_config('minion', from_scratch=True) @skipIf(HAS_ZMQ_IOLOOP is False, 'PyZMQ version must be >= 14.0.1 to run these tests.') @skipIf( StrictVersion(zmq.__version__) < StrictVersion('14.0.1'), 'PyZMQ must be >= 14.0.1 to run these tests.') class TestSaltAPIHandler(_SaltnadoIntegrationTestCase): def get_app(self): urls = [('/', saltnado.SaltAPIHandler)] application = self.build_tornado_app(urls) application.event_listener = saltnado.EventListener({}, self.opts) return application def test_root(self): ''' Test the root path which returns the list of clients we support ''' response = self.fetch(
import ipaddress import platform # Import Salt libs from salt.utils.versions import StrictVersion # Import 3rd party libs # I don't understand why I need this import, but the linter fails without it from salt.ext.six.moves import range IS_WINDOWS = platform.system() == 'Windows' __virtualname__ = 'win_network' if IS_WINDOWS: USE_WMI = StrictVersion(platform.version()) < StrictVersion('6.2') if USE_WMI: import wmi import salt.utils.winapi else: import clr from System.Net import NetworkInformation enum_adapter_types = { 1: 'Unknown', 6: 'Ethernet', 9: 'TokenRing', 15: 'FDDI', 20: 'BasicISDN', 21: 'PrimaryISDN', 23: 'PPP',
import ipaddress import platform # Import 3rd party libs # I don't understand why I need this import, but the linter fails without it from salt.ext.six.moves import range # Import Salt libs from salt.utils.versions import StrictVersion IS_WINDOWS = platform.system() == "Windows" __virtualname__ = "win_network" if IS_WINDOWS: USE_WMI = StrictVersion(platform.version()) < StrictVersion("6.2") if USE_WMI: import wmi import salt.utils.winapi else: import clr from System.Net import NetworkInformation enum_adapter_types = { 1: "Unknown", 6: "Ethernet", 9: "TokenRing", 15: "FDDI", 20: "BasicISDN", 21: "PrimaryISDN", 23: "PPP",
HAS_ZMQ_IOLOOP = bool(zmq) class _SaltnadoIntegrationTestCase(SaltnadoTestCase): # pylint: disable=abstract-method @property def opts(self): return self.get_config("client_config", from_scratch=True) @property def mod_opts(self): return self.get_config("minion", from_scratch=True) @skipIf(HAS_ZMQ_IOLOOP is False, "PyZMQ version must be >= 14.0.1 to run these tests.") @skipIf( StrictVersion(zmq.__version__) < StrictVersion("14.0.1"), "PyZMQ must be >= 14.0.1 to run these tests.", ) class TestSaltAPIHandler(_SaltnadoIntegrationTestCase): def setUp(self): super(TestSaltAPIHandler, self).setUp() os.environ["ASYNC_TEST_TIMEOUT"] = "300" def get_app(self): urls = [("/", saltnado.SaltAPIHandler)] application = self.build_tornado_app(urls) application.event_listener = saltnado.EventListener({}, self.opts) self.application = application return application
HAS_ZMQ_IOLOOP = False class _SaltnadoIntegrationTestCase(SaltnadoTestCase): # pylint: disable=abstract-method @property def opts(self): return self.get_config('client_config', from_scratch=True) @property def mod_opts(self): return self.get_config('minion', from_scratch=True) @skipIf(HAS_ZMQ_IOLOOP is False, 'PyZMQ version must be >= 14.0.1 to run these tests.') @skipIf(StrictVersion(zmq.__version__) < StrictVersion('14.0.1'), 'PyZMQ must be >= 14.0.1 to run these tests.') class TestSaltAPIHandler(_SaltnadoIntegrationTestCase): def get_app(self): urls = [('/', saltnado.SaltAPIHandler)] application = self.build_tornado_app(urls) application.event_listener = saltnado.EventListener({}, self.opts) return application def test_root(self): ''' Test the root path which returns the list of clients we support ''' response = self.fetch('/', connect_timeout=30,