function
stringlengths 11
56k
| repo_name
stringlengths 5
60
| features
sequence |
---|---|---|
def _assert_sid_is_in_chain(sid, pid):
if not sid or not pid:
return
chain_model = _get_chain_by_pid(pid)
if not chain_model or not chain_model.sid:
return
if chain_model.sid.did != sid:
raise d1_common.types.exceptions.ServiceFailure(
0,
"Attempted to create object in chain with non-matching SID. "
'existing_sid="{}", new_sid="{}"'.format(chain_model.sid.did, sid),
) | DataONEorg/d1_python | [
13,
6,
13,
17,
1464710460
] |
def _get_chain_by_pid(pid):
"""Find chain by pid.
Return None if not found.
"""
try:
return d1_gmn.app.models.ChainMember.objects.get(pid__did=pid).chain
except d1_gmn.app.models.ChainMember.DoesNotExist:
pass | DataONEorg/d1_python | [
13,
6,
13,
17,
1464710460
] |
def _update_sid_to_last_existing_pid_map(pid):
"""Set chain head PID to the last existing object in the chain to which ``pid``
belongs. If SID has been set for chain, it resolves to chain head PID.
Intended to be called in MNStorage.delete() and other chain manipulation.
Preconditions:
- ``pid`` must exist and be verified to be a PID.
d1_gmn.app.views.asserts.is_existing_object()
"""
last_pid = _find_head_or_latest_connected(pid)
chain_model = _get_chain_by_pid(last_pid)
if not chain_model:
return
chain_model.head_pid = d1_gmn.app.did.get_or_create_did(last_pid)
chain_model.save() | DataONEorg/d1_python | [
13,
6,
13,
17,
1464710460
] |
def _map_sid_to_pid(chain_model, sid, pid):
if sid is not None:
chain_model.sid = d1_gmn.app.did.get_or_create_did(sid)
chain_model.head_pid = d1_gmn.app.did.get_or_create_did(pid)
chain_model.save() | DataONEorg/d1_python | [
13,
6,
13,
17,
1464710460
] |
def _get_all_chain_member_queryset_by_chain(chain_model):
return d1_gmn.app.models.ChainMember.objects.filter(chain=chain_model) | DataONEorg/d1_python | [
13,
6,
13,
17,
1464710460
] |
def _cut_tail_from_chain(sciobj_model):
new_tail_model = d1_gmn.app.model_util.get_sci_model(sciobj_model.obsoleted_by.did)
new_tail_model.obsoletes = None
sciobj_model.obsoleted_by = None
sciobj_model.save()
new_tail_model.save() | DataONEorg/d1_python | [
13,
6,
13,
17,
1464710460
] |
def _is_head(sciobj_model):
return sciobj_model.obsoletes and not sciobj_model.obsoleted_by | DataONEorg/d1_python | [
13,
6,
13,
17,
1464710460
] |
def _set_revision_reverse(to_pid, from_pid, is_obsoletes):
try:
sciobj_model = d1_gmn.app.model_util.get_sci_model(from_pid)
except d1_gmn.app.models.ScienceObject.DoesNotExist:
return
if not d1_gmn.app.did.is_existing_object(to_pid):
return
did_model = d1_gmn.app.did.get_or_create_did(to_pid)
if is_obsoletes:
sciobj_model.obsoletes = did_model
else:
sciobj_model.obsoleted_by = did_model
sciobj_model.save() | DataONEorg/d1_python | [
13,
6,
13,
17,
1464710460
] |
def snmp_version(self):
if self._values['snmp_version'] is None:
return None
return str(self._values['snmp_version']) | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def port(self):
if self._values['port'] is None:
return None
return int(self._values['port']) | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def api_params(self):
result = {}
for api_attribute in self.api_attributes:
if self.api_map is not None and api_attribute in self.api_map:
result[api_attribute] = getattr(self, self.api_map[api_attribute])
else:
result[api_attribute] = getattr(self, api_attribute)
result = self._filter_params(result)
return result | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def network(self):
if self._values['network'] is None:
return None
network = str(self._values['network'])
if network == 'management':
return 'mgmt'
elif network == 'default':
return ''
else:
return network | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def network(self):
return None | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def __init__(self, client):
self.client = client | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def is_version_non_networked(self):
"""Checks to see if the TMOS version is less than 13
Anything less than BIG-IP 13.x does not support users
on different partitions.
:return: Bool
"""
version = self.client.api.tmos_version
if LooseVersion(version) < LooseVersion('12.1.0'):
return True
else:
return False | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def __init__(self, client):
self.client = client
self.have = None | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def exists(self):
result = self.client.api.tm.sys.snmp.traps_s.trap.exists(
name=self.want.name,
partition=self.want.partition
)
return result | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def create(self):
self._set_changed_options()
if self.client.check_mode:
return True
if all(getattr(self.want, v) is None for v in self.required_resources):
raise F5ModuleError(
"You must specify at least one of "
', '.join(self.required_resources)
)
self.create_on_device()
return True | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def update(self):
self.have = self.read_current_from_device()
if not self.should_update():
return False
if self.client.check_mode:
return True
self.update_on_device()
return True | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def create_on_device(self):
params = self.want.api_params()
self.client.api.tm.sys.snmp.traps_s.trap.create(
name=self.want.name,
partition=self.want.partition,
**params
) | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def remove(self):
if self.client.check_mode:
return True
self.remove_from_device()
if self.exists():
raise F5ModuleError("Failed to delete the snmp trap")
return True | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def __init__(self, client):
super(NetworkedManager, self).__init__(client)
self.required_resources = [
'version', 'community', 'destination', 'port', 'network'
]
self.want = NetworkedParameters(self.client.module.params)
self.changes = NetworkedParameters() | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def _update_changed_options(self):
changed = {}
for key in NetworkedParameters.updatables:
if getattr(self.want, key) is not None:
attr1 = getattr(self.want, key)
attr2 = getattr(self.have, key)
if attr1 != attr2:
changed[key] = attr1
if changed:
self.changes = NetworkedParameters(changed)
return True
return False | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def _ensure_network(self, result):
# BIG-IP's value for "default" is that the key does not
# exist. This conflicts with our purpose of having a key
# not exist (which we equate to "i dont want to change that"
# therefore, if we load the information from BIG-IP and
# find that there is no 'network' key, that is BIG-IP's
# way of saying that the network value is "default"
if 'network' not in result:
result['network'] = 'default' | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def __init__(self, client):
super(NonNetworkedManager, self).__init__(client)
self.required_resources = [
'version', 'community', 'destination', 'port'
]
self.want = NonNetworkedParameters(self.client.module.params)
self.changes = NonNetworkedParameters() | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def _update_changed_options(self):
changed = {}
for key in NonNetworkedParameters.updatables:
if getattr(self.want, key) is not None:
attr1 = getattr(self.want, key)
attr2 = getattr(self.have, key)
if attr1 != attr2:
changed[key] = attr1
if changed:
self.changes = NonNetworkedParameters(changed)
return True
return False | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def __init__(self):
self.supports_check_mode = True
self.argument_spec = dict(
name=dict(
required=True
),
snmp_version=dict(
choices=['1', '2c']
),
community=dict(),
destination=dict(),
port=dict(),
network=dict(
choices=['other', 'management', 'default']
),
state=dict(
default='present',
choices=['absent', 'present']
)
)
self.f5_product_name = 'bigip' | mcgonagle/ansible_f5 | [
10,
27,
10,
1,
1478300759
] |
def test_enable_command_requires_a_password(self, t):
t.write("enable")
t.read("Password: ")
t.write_invisible(t.conf["extra"]["password"])
t.read("my_switch#") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_wrong_password(self, t):
t.write("enable")
t.read("Password: ")
t.write_invisible("hello_world")
t.readln("% Access denied")
t.readln("")
t.read("my_switch>") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_no_password_works_for_legacy_reasons(self, t):
t.write("enable")
t.read("Password: ")
t.write_invisible("")
t.read("my_switch#") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_exiting_loses_the_connection(self, t):
t.write("enable")
t.read("Password: ")
t.write_invisible(t.conf["extra"]["password"])
t.read("my_switch#")
t.write("exit")
t.read_eof() | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_no_such_command_return_to_prompt(self, t):
enable(t)
t.write("shizzle")
t.readln("No such command : shizzle")
t.read("my_switch#") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_command_copy_failing(self, t, read_tftp):
read_tftp.side_effect = Exception("Stuff")
enable(t)
t.write("copy tftp://1.2.3.4/my-file system:/running-config")
t.read("Destination filename [running-config]? ")
t.write("gneh")
t.readln("Accessing tftp://1.2.3.4/my-file...")
t.readln("Error opening tftp://1.2.3.4/my-file (Timed out)")
t.read("my_switch#")
read_tftp.assert_called_with("1.2.3.4", "my-file") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_command_copy_success(self, t, read_tftp):
enable(t)
t.write("copy tftp://1.2.3.4/my-file system:/running-config")
t.read("Destination filename [running-config]? ")
t.write_raw("\r")
t.wait_for("\r\n")
t.readln("Accessing tftp://1.2.3.4/my-file...")
t.readln("Done (or some official message...)")
t.read("my_switch#")
read_tftp.assert_called_with("1.2.3.4", "my-file") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_command_show_run_int_vlan_empty(self, t):
enable(t)
t.write("terminal length 0")
t.read("my_switch#")
t.write("show run vlan 120")
t.readln("Building configuration...")
t.readln("")
t.readln("Current configuration:")
t.readln("end")
t.readln("")
t.read("my_switch#") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_command_add_vlan(self, t):
enable(t)
t.write("conf t")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("vlan 123")
t.read("my_switch(config-vlan)#")
t.write("name shizzle")
t.read("my_switch(config-vlan)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
t.write("show run vlan 123")
t.readln("Building configuration...")
t.readln("")
t.readln("Current configuration:")
t.readln("!")
t.readln("vlan 123")
t.readln(" name shizzle")
t.readln("end")
t.readln("")
t.read("my_switch#")
remove_vlan(t, "123")
t.write("show running-config vlan 123")
t.readln("Building configuration...")
t.readln("")
t.readln("Current configuration:")
t.readln("end")
t.read("") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_command_assign_access_vlan_to_port(self, t):
enable(t)
create_vlan(t, "123")
set_interface_on_vlan(t, "FastEthernet0/1", "123")
assert_interface_configuration(t, "Fa0/1", [
"interface FastEthernet0/1",
" switchport access vlan 123",
" switchport mode access",
"end"])
configuring_interface(t, "FastEthernet0/1", do="no switchport access vlan")
assert_interface_configuration(t, "Fa0/1", [
"interface FastEthernet0/1",
" switchport mode access",
"end"])
configuring_interface(t, "FastEthernet0/1", do="no switchport mode access")
assert_interface_configuration(t, "Fa0/1", [
"interface FastEthernet0/1",
"end"])
remove_vlan(t, "123") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_show_vlan_brief(self, t):
enable(t)
create_vlan(t, "123")
create_vlan(t, "3333", "some-name")
create_vlan(t, "2222", "your-name-is-way-too-long-for-this-pretty-printed-interface-man")
set_interface_on_vlan(t, "FastEthernet0/1", "123")
t.write("show vlan brief")
t.readln("")
t.readln("VLAN Name Status Ports")
t.readln("---- -------------------------------- --------- -------------------------------")
t.readln("1 default active Fa0/2, Fa0/3, Fa0/4, Fa0/5")
t.readln(" Fa0/6, Fa0/7, Fa0/8, Fa0/9")
t.readln(" Fa0/10, Fa0/11, Fa0/12")
t.readln("123 VLAN123 active Fa0/1")
t.readln("2222 your-name-is-way-too-long-for-th active")
t.readln("3333 some-name active")
t.read("my_switch#")
revert_switchport_mode_access(t, "FastEthernet0/1")
remove_vlan(t, "123")
remove_vlan(t, "2222")
remove_vlan(t, "3333") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_show_vlan(self, t):
enable(t)
create_vlan(t, "123")
create_vlan(t, "3333", "some-name")
create_vlan(t, "2222", "your-name-is-way-too-long-for-this-pretty-printed-interface-man")
set_interface_on_vlan(t, "FastEthernet0/1", "123")
t.write("show vlan")
t.readln("")
t.readln("VLAN Name Status Ports")
t.readln("---- -------------------------------- --------- -------------------------------")
t.readln("1 default active Fa0/2, Fa0/3, Fa0/4, Fa0/5")
t.readln(" Fa0/6, Fa0/7, Fa0/8, Fa0/9")
t.readln(" Fa0/10, Fa0/11, Fa0/12")
t.readln("123 VLAN123 active Fa0/1")
t.readln("2222 your-name-is-way-too-long-for-th active")
t.readln("3333 some-name active")
t.readln("")
t.readln("VLAN Type SAID MTU Parent RingNo BridgeNo Stp BrdgMode Trans1 Trans2")
t.readln("---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------")
t.readln("1 enet 100001 1500 - - - - - 0 0")
t.readln("123 enet 100123 1500 - - - - - 0 0")
t.readln("2222 enet 102222 1500 - - - - - 0 0")
t.readln("3333 enet 103333 1500 - - - - - 0 0")
t.readln("")
t.readln("Remote SPAN VLANs")
t.readln("------------------------------------------------------------------------------")
t.readln("")
t.readln("")
t.readln("Primary Secondary Type Ports")
t.readln("------- --------- ----------------- ------------------------------------------")
t.readln("")
t.read("my_switch#")
revert_switchport_mode_access(t, "FastEthernet0/1")
remove_vlan(t, "123")
remove_vlan(t, "2222")
remove_vlan(t, "3333") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_shutting_down(self, t):
enable(t)
configuring_interface(t, "FastEthernet 0/3", do="shutdown")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" shutdown",
"end"])
configuring_interface(t, "FastEthernet 0/3", do="no shutdown")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
"end"]) | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_configure_trunk_port(self, t):
enable(t)
configuring_interface(t, "Fa0/3", do="switchport mode trunk")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport mode trunk",
"end"])
# not really added because all vlan are in trunk by default on cisco
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan add 123")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan none")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport trunk allowed vlan none",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan add 123")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport trunk allowed vlan 123",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan add 124,126-128")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport trunk allowed vlan 123,124,126-128",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan remove 123-124,127")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport trunk allowed vlan 126,128",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan all")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="switchport trunk allowed vlan 123-124,127")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport trunk allowed vlan 123,124,127",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="no switchport trunk allowed vlan")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" switchport mode trunk",
"end"])
configuring_interface(t, "Fa0/3", do="no switchport mode")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
"end"]) | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_configure_native_vlan(self, t):
enable(t)
configuring_interface(t, "FastEthernet0/2", do="switchport trunk native vlan 555")
assert_interface_configuration(t, "Fa0/2", [
"interface FastEthernet0/2",
" switchport trunk native vlan 555",
"end"])
configuring_interface(t, "FastEthernet0/2", do="no switchport trunk native vlan")
assert_interface_configuration(t, "Fa0/2", [
"interface FastEthernet0/2",
"end"]) | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_setup_an_interface(self, t):
enable(t)
create_vlan(t, "2999")
create_interface_vlan(t, "2999")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring_interface_vlan(t, "2999", do="description hey ho")
configuring_interface_vlan(t, "2999", do="ip address 1.1.1.2 255.255.255.0")
configuring_interface_vlan(t, "2999", do="standby 1 ip 1.1.1.1")
configuring_interface_vlan(t, "2999", do='standby 1 timers 5 15')
configuring_interface_vlan(t, "2999", do='standby 1 priority 110')
configuring_interface_vlan(t, "2999", do='standby 1 preempt delay minimum 60')
configuring_interface_vlan(t, "2999", do='standby 1 authentication VLAN2999')
configuring_interface_vlan(t, "2999", do='standby 1 track 10 decrement 50')
configuring_interface_vlan(t, "2999", do='standby 1 track 20 decrement 50')
configuring_interface_vlan(t, "2999", do='no ip proxy-arp')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" ip address 1.1.1.2 255.255.255.0",
" no ip proxy-arp",
" standby 1 ip 1.1.1.1",
" standby 1 timers 5 15",
" standby 1 priority 110",
" standby 1 preempt delay minimum 60",
" standby 1 authentication VLAN2999",
" standby 1 track 10 decrement 50",
" standby 1 track 20 decrement 50",
"end"])
configuring_interface_vlan(t, "2999", do="ip address 2.2.2.2 255.255.255.0")
configuring_interface_vlan(t, "2999", do="standby 1 ip 2.2.2.1")
configuring_interface_vlan(t, "2999", do="standby 1 ip 2.2.2.3 secondary")
configuring_interface_vlan(t, "2999", do="no standby 1 authentication")
configuring_interface_vlan(t, "2999", do="standby 1 preempt delay minimum 42")
configuring_interface_vlan(t, "2999", do="no standby 1 priority")
configuring_interface_vlan(t, "2999", do="no standby 1 timers")
configuring_interface_vlan(t, "2999", do="no standby 1 track 10")
configuring_interface_vlan(t, "2999", do="ip proxy-arp")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" ip address 2.2.2.2 255.255.255.0",
" standby 1 ip 2.2.2.1",
" standby 1 ip 2.2.2.3 secondary",
" standby 1 preempt delay minimum 42",
" standby 1 track 20 decrement 50",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 ip 2.2.2.3")
configuring_interface_vlan(t, "2999", do="no standby 1 preempt delay")
configuring_interface_vlan(t, "2999", do="no standby 1 track 20")
configuring_interface_vlan(t, "2999", do="")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" ip address 2.2.2.2 255.255.255.0",
" standby 1 ip 2.2.2.1",
" standby 1 preempt",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 ip 2.2.2.1")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" ip address 2.2.2.2 255.255.255.0",
" standby 1 preempt",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1")
configuring_interface_vlan(t, "2999", do="no description")
configuring_interface_vlan(t, "2999", do="")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" ip address 2.2.2.2 255.255.255.0",
"end"])
configuring(t, do="no interface vlan 2999")
t.write("show run int vlan 2999")
t.readln("\s*\^", regex=True)
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch#")
remove_vlan(t, "2999") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_partial_standby_properties(self, t):
enable(t)
create_vlan(t, "2999")
create_interface_vlan(t, "2999")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring_interface_vlan(t, "2999", do='standby 1 timers 5 15')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 timers 5 15",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 timers")
configuring_interface_vlan(t, "2999", do='standby 1 priority 110')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 priority 110",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 priority")
configuring_interface_vlan(t, "2999", do='standby 1 preempt delay minimum 60')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 preempt delay minimum 60",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 preempt")
configuring_interface_vlan(t, "2999", do='standby 1 authentication VLAN2999')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 authentication VLAN2999",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 authentication")
configuring_interface_vlan(t, "2999", do='standby 1 track 10 decrement 50')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 track 10 decrement 50",
"end"])
configuring_interface_vlan(t, "2999", do="no standby 1 track 10")
configuring(t, do="no interface vlan 2999")
remove_vlan(t, "2999") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_partial_standby_ip_definition(self, t):
enable(t)
create_vlan(t, "2999")
create_interface_vlan(t, "2999")
configuring_interface_vlan(t, "2999", do='standby 1 ip')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 ip",
"end"])
configuring_interface_vlan(t, "2999", do='no standby 1 ip')
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface vlan 2999")
t.read("my_switch(config-if)#")
t.write("standby 1 ip 1..1.1")
t.readln(" ^")
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch(config-if)#")
t.write("standby 1 ip 1.1.1.1")
t.readln("% Warning: address is not within a subnet on this interface")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring_interface_vlan(t, "2999", do="ip address 1.1.1.2 255.255.255.0")
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface vlan 2999")
t.read("my_switch(config-if)#")
t.write("standby 1 ip 2.1.1.1")
t.readln("% Warning: address is not within a subnet on this interface")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
configuring_interface_vlan(t, "2999", do='standby 1 ip 1.1.1.1')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" ip address 1.1.1.2 255.255.255.0",
" standby 1 ip 1.1.1.1",
"end"])
configuring_interface_vlan(t, "2999", do='standby 1 ip')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" ip address 1.1.1.2 255.255.255.0",
" standby 1 ip 1.1.1.1",
"end"])
configuring_interface_vlan(t, "2999", do="no ip address 1.1.1.2 255.255.255.0")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby 1 ip 1.1.1.1",
"end"])
configuring_interface_vlan(t, "2999", do='no standby 1 ip 1.1.1.1')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring(t, do="no interface vlan 2999")
remove_vlan(t, "2999") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_creating_a_port_channel(self, t):
enable(t)
create_port_channel_interface(t, '1')
configuring_port_channel(t, '1', 'description HELLO')
configuring_port_channel(t, '1', 'switchport trunk encapsulation dot1q')
configuring_port_channel(t, '1', 'switchport trunk native vlan 998')
configuring_port_channel(t, '1', 'switchport trunk allowed vlan 6,4087-4089,4091,4093')
configuring_port_channel(t, '1', 'switchport mode trunk')
assert_interface_configuration(t, 'Port-channel1', [
"interface Port-channel1",
" description HELLO",
" switchport trunk encapsulation dot1q",
" switchport trunk native vlan 998",
" switchport trunk allowed vlan 6,4087-4089,4091,4093",
" switchport mode trunk",
"end"
])
t.write("show etherchannel summary")
t.readln("Flags: D - down P - bundled in port-channel")
t.readln(" I - stand-alone s - suspended")
t.readln(" H - Hot-standby (LACP only)")
t.readln(" R - Layer3 S - Layer2")
t.readln(" U - in use f - failed to allocate aggregator")
t.readln("")
t.readln(" M - not in use, minimum links not met")
t.readln(" u - unsuitable for bundling")
t.readln(" w - waiting to be aggregated")
t.readln(" d - default port")
t.readln("")
t.readln("")
t.readln("Number of channel-groups in use: 1")
t.readln("Number of aggregators: 1")
t.readln("")
t.readln("Group Port-channel Protocol Ports")
t.readln("------+-------------+-----------+-----------------------------------------------")
t.readln("1 Po1(S) LACP ")
t.readln("")
t.read("my_switch#")
configuring(t, do="no interface port-channel 1")
t.write("show run int po1")
t.readln("\s*\^", regex=True)
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch#") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_port_channel_is_automatically_created_when_adding_a_port_to_it(self, t):
enable(t)
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface FastEthernet0/1")
t.read("my_switch(config-if)#")
t.write("channel-group 2 mode active")
t.readln("Creating a port-channel interface Port-channel 2")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, 'fa0/1', [
"interface FastEthernet0/1",
" channel-group 2 mode active",
"end"
])
assert_interface_configuration(t, 'po2', [
"interface Port-channel2",
"end"
])
t.write("show etherchannel summary")
t.readln("Flags: D - down P - bundled in port-channel")
t.readln(" I - stand-alone s - suspended")
t.readln(" H - Hot-standby (LACP only)")
t.readln(" R - Layer3 S - Layer2")
t.readln(" U - in use f - failed to allocate aggregator")
t.readln("")
t.readln(" M - not in use, minimum links not met")
t.readln(" u - unsuitable for bundling")
t.readln(" w - waiting to be aggregated")
t.readln(" d - default port")
t.readln("")
t.readln("")
t.readln("Number of channel-groups in use: 1")
t.readln("Number of aggregators: 1")
t.readln("")
t.readln("Group Port-channel Protocol Ports")
t.readln("------+-------------+-----------+-----------------------------------------------")
t.readln("2 Po2(SU) LACP Fa0/1(P)")
t.readln("")
t.read("my_switch#")
configuring(t, do="no interface port-channel 2")
configuring_interface(t, interface="fa0/1", do="no channel-group 2 mode on")
assert_interface_configuration(t, "fa0/1", [
"interface FastEthernet0/1",
"end"
]) | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_port_channel_is_not_automatically_created_when_adding_a_port_to_it_if_its_already_created(self, t):
enable(t)
create_port_channel_interface(t, '14')
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface FastEthernet0/1")
t.read("my_switch(config-if)#")
t.write("channel-group 14 mode active")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, "fa0/1", [
"interface FastEthernet0/1",
" channel-group 14 mode active",
"end"
])
configuring_interface(t, interface="fa0/1", do="no channel-group 14 mode on")
assert_interface_configuration(t, "fa0/1", [
"interface FastEthernet0/1",
"end"
])
configuring(t, do="no interface port-channel 14") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_setting_secondary_ips(self, t):
enable(t)
create_interface_vlan(t, "2999")
configuring_interface_vlan(t, "2999", do="description hey ho")
configuring_interface_vlan(t, "2999", do="no ip redirects")
configuring_interface_vlan(t, "2999", do="ip address 1.1.1.1 255.255.255.0")
configuring_interface_vlan(t, "2999", do="ip address 2.2.2.1 255.255.255.0 secondary")
configuring_interface_vlan(t, "2999", do="ip address 4.4.4.1 255.255.255.0 secondary")
configuring_interface_vlan(t, "2999", do="ip address 3.3.3.1 255.255.255.0 secondary")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" ip address 2.2.2.1 255.255.255.0 secondary",
" ip address 4.4.4.1 255.255.255.0 secondary",
" ip address 3.3.3.1 255.255.255.0 secondary",
" ip address 1.1.1.1 255.255.255.0",
" no ip redirects",
"end"])
configuring_interface_vlan(t, "2999", do="no ip address")
configuring_interface_vlan(t, "2999", do="ip redirects")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" description hey ho",
" no ip address",
"end"])
configuring(t, do="no interface vlan 2999") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_setting_access_group(self, t):
enable(t)
create_interface_vlan(t, "2999")
configuring_interface_vlan(t, "2999", do="ip access-group SHNITZLE in")
configuring_interface_vlan(t, "2999", do="ip access-group WHIZZLE out")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" ip access-group SHNITZLE in",
" ip access-group WHIZZLE out",
"end"])
configuring_interface_vlan(t, "2999", do="no ip access-group in")
configuring_interface_vlan(t, "2999", do="no ip access-group WHIZZLE out")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring(t, do="no interface vlan 2999") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_removing_ip_address(self, t):
enable(t)
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface vlan2999")
t.read("my_switch(config-if)#")
t.write("ip address 1.1.1.1 255.255.255.0")
t.read("my_switch(config-if)#")
t.write("ip address 2.2.2.2 255.255.255.0 secondary")
t.read("my_switch(config-if)#")
t.write("no ip address 1.1.1.1 255.255.255.0")
t.readln("Must delete secondary before deleting primary")
t.read("my_switch(config-if)#")
t.write("no ip address 2.2.2.2 255.255.255.0 secondary")
t.read("my_switch(config-if)#")
t.write("no ip address 1.1.1.1 255.255.255.0")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring(t, do="no interface vlan 2999") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_show_ip_interface(self, t):
enable(t)
create_vlan(t, "1000")
create_interface_vlan(t, "1000")
create_vlan(t, "2000")
create_vlan(t, "3000")
create_interface_vlan(t, "3000")
configuring_interface_vlan(t, "3000", do="ip address 1.1.1.1 255.255.255.0")
create_interface_vlan(t, "4000")
configuring_interface_vlan(t, "4000", do="ip vrf forwarding DEFAULT-LAN")
configuring_interface_vlan(t, "4000", do="ip address 2.2.2.2 255.255.255.0")
configuring_interface_vlan(t, "4000", do="ip address 4.2.2.2 255.255.255.0 secondary")
configuring_interface_vlan(t, "4000", do="ip address 3.2.2.2 255.255.255.0 secondary")
configuring_interface_vlan(t, "4000", do="ip address 3.2.2.2 255.255.255.128 secondary")
configuring_interface_vlan(t, "4000", do="ip access-group shizzle in")
configuring_interface_vlan(t, "4000", do="ip access-group whizzle out")
t.write("show ip interface")
t.readln("Vlan1000 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("Vlan3000 is down, line protocol is down")
t.readln(" Internet address is 1.1.1.1/24")
t.readln(" Outgoing access list is not set")
t.readln(" Inbound access list is not set")
t.readln("Vlan4000 is down, line protocol is down")
t.readln(" Internet address is 2.2.2.2/24")
t.readln(" Secondary address 4.2.2.2/24")
t.readln(" Secondary address 3.2.2.2/25")
t.readln(" Outgoing access list is whizzle")
t.readln(" Inbound access list is shizzle")
t.readln(" VPN Routing/Forwarding \"DEFAULT-LAN\"")
t.readln("FastEthernet0/1 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/2 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/3 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/4 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/5 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/6 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/7 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/8 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/9 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/10 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/11 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/12 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.read("my_switch#")
t.write("show ip interface vlan 4000")
t.readln("Vlan4000 is down, line protocol is down")
t.readln(" Internet address is 2.2.2.2/24")
t.readln(" Secondary address 4.2.2.2/24")
t.readln(" Secondary address 3.2.2.2/25")
t.readln(" Outgoing access list is whizzle")
t.readln(" Inbound access list is shizzle")
t.readln(" VPN Routing/Forwarding \"DEFAULT-LAN\"")
t.read("my_switch#")
t.write("show ip interface vlan1000")
t.readln("Vlan1000 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.read("my_switch#")
configuring(t, do="no interface vlan 1000")
configuring(t, do="no interface vlan 3000")
configuring(t, do="no interface vlan 4000")
remove_vlan(t, "1000")
remove_vlan(t, "2000")
remove_vlan(t, "3000") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_assigning_a_secondary_ip_as_the_primary_removes_it_from_secondary_and_removes_the_primary(self, t):
enable(t)
create_interface_vlan(t, "4000")
configuring_interface_vlan(t, "4000", do="ip address 2.2.2.2 255.255.255.0")
configuring_interface_vlan(t, "4000", do="ip address 4.2.2.2 255.255.255.0 secondary")
configuring_interface_vlan(t, "4000", do="ip address 3.2.2.2 255.255.255.0 secondary")
configuring_interface_vlan(t, "4000", do="ip address 3.2.2.2 255.255.255.128")
assert_interface_configuration(t, "Vlan4000", [
"interface Vlan4000",
" ip address 4.2.2.2 255.255.255.0 secondary",
" ip address 3.2.2.2 255.255.255.128",
"end"])
configuring(t, do="no interface vlan 4000") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_overlapping_ips(self, t):
enable(t)
create_vlan(t, "1000")
create_interface_vlan(t, "1000")
create_vlan(t, "2000")
create_interface_vlan(t, "2000")
configuring_interface_vlan(t, "1000", do="ip address 2.2.2.2 255.255.255.0")
configuring_interface_vlan(t, "1000", do="ip address 3.3.3.3 255.255.255.0 secondary")
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface vlan2000")
t.read("my_switch(config-if)#")
t.write("ip address 2.2.2.75 255.255.255.128")
t.readln("% 2.2.2.0 overlaps with secondary address on Vlan1000")
t.read("my_switch(config-if)#")
t.write("ip address 3.3.3.4 255.255.255.128")
t.readln("% 3.3.3.0 is assigned as a secondary address on Vlan1000")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
configuring(t, do="no interface vlan 2000")
remove_vlan(t, "2000")
configuring(t, do="no interface vlan 1000")
remove_vlan(t, "1000") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_unknown_ip_interface(self, t):
enable(t)
t.write("show ip interface Vlan2345")
t.readln(" ^")
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch#") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_removing_ip_needs_to_compare_objects_better(self, t):
enable(t)
create_vlan(t, "1000")
create_interface_vlan(t, "1000")
configuring_interface_vlan(t, "1000", do="ip address 1.1.1.1 255.255.255.0")
configuring_interface_vlan(t, "1000", do="ip address 1.1.1.2 255.255.255.0 secondary")
configuring_interface_vlan(t, "1000", do="ip address 1.1.1.3 255.255.255.0 secondary")
configuring_interface_vlan(t, "1000", do="no ip address 1.1.1.3 255.255.255.0 secondary")
t.write("show ip interface vlan 1000")
t.readln("Vlan1000 is down, line protocol is down")
t.readln(" Internet address is 1.1.1.1/24")
t.readln(" Secondary address 1.1.1.2/24")
t.readln(" Outgoing access list is not set")
t.readln(" Inbound access list is not set")
t.read("my_switch#")
configuring(t, do="no interface vlan 1000")
remove_vlan(t, "1000") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_extreme_vlan_range(self, t):
enable(t)
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("vlan -1")
t.readln("Command rejected: Bad VLAN list - character #1 ('-') delimits a VLAN number")
t.readln(" which is out of the range 1..4094.")
t.read("my_switch(config)#")
t.write("vlan 0")
t.readln("Command rejected: Bad VLAN list - character #X (EOL) delimits a VLAN")
t.readln("number which is out of the range 1..4094.")
t.read("my_switch(config)#")
t.write("vlan 1")
t.read("my_switch(config-vlan)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("vlan 4094")
t.read("my_switch(config-vlan)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("no vlan 4094")
t.read("my_switch(config)#")
t.write("vlan 4095")
t.readln("Command rejected: Bad VLAN list - character #X (EOL) delimits a VLAN")
t.readln("number which is out of the range 1..4094.")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_full_running_config_and_pipe_begin_support(self, t):
enable(t)
create_vlan(t, "1000", name="hello")
create_interface_vlan(t, "1000")
configuring_interface(t, "Fa0/2", do="switchport mode trunk")
configuring_interface(t, "Fa0/2", do="switchport trunk allowed vlan 125")
t.write("show running | beg vlan")
t.readln("vlan 1")
t.readln("!")
t.readln("vlan 1000")
t.readln(" name hello")
t.readln("!")
t.readln("interface FastEthernet0/1")
t.readln("!")
t.readln("interface FastEthernet0/2")
t.readln(" switchport trunk allowed vlan 125")
t.readln(" switchport mode trunk")
t.readln("!")
t.readln("interface FastEthernet0/3")
t.readln("!")
t.readln("interface FastEthernet0/4")
t.readln("!")
t.readln("interface FastEthernet0/5")
t.readln("!")
t.readln("interface FastEthernet0/6")
t.readln("!")
t.readln("interface FastEthernet0/7")
t.readln("!")
t.readln("interface FastEthernet0/8")
t.readln("!")
t.readln("interface FastEthernet0/9")
t.readln("!")
t.readln("interface FastEthernet0/10")
t.readln("!")
t.readln("interface FastEthernet0/11")
t.readln("!")
t.readln("interface FastEthernet0/12")
t.readln("!")
t.readln("interface Vlan1000")
t.readln(" no ip address")
t.readln("!")
t.readln("end")
t.readln("")
t.read("my_switch#")
configuring_interface(t, "Fa0/2", do="no switchport mode trunk")
configuring_interface(t, "Fa0/2", do="no switchport trunk allowed vlan")
configuring(t, do="no interface vlan 1000")
remove_vlan(t, "1000") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_pipe_inc_support(self, t):
enable(t)
create_vlan(t, "1000", name="hello")
t.write("show running | inc vlan")
t.readln("vlan 1")
t.readln("vlan 1000")
t.read("my_switch#")
remove_vlan(t, "1000") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_ip_vrf(self, t):
enable(t)
t.write("conf t")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("ip vrf SOME-LAN")
t.read("my_switch(config-vrf)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("no ip vrf SOME-LAN")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_ip_vrf_forwarding(self, t):
enable(t)
t.write("conf t")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("ip vrf SOME-LAN")
t.read("my_switch(config-vrf)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("interface Fa0/2")
t.read("my_switch(config-if)#")
t.write("ip vrf forwarding NOT-DEFAULT-LAN")
t.readln("% VRF NOT-DEFAULT-LAN not configured.")
t.read("my_switch(config-if)#")
t.write("ip vrf forwarding SOME-LAN")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, "Fa0/2", [
"interface FastEthernet0/2",
" ip vrf forwarding SOME-LAN",
"end"])
t.write("conf t")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("no ip vrf SOME-LAN")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, "Fa0/2", [
"interface FastEthernet0/2",
"end"]) | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_ip_vrf_default_lan(self, t):
enable(t)
t.write("conf t")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface Fa0/2")
t.read("my_switch(config-if)#")
t.write("ip vrf forwarding DEFAULT-LAN")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, "Fa0/2", [
"interface FastEthernet0/2",
" ip vrf forwarding DEFAULT-LAN",
"end"])
t.write("conf t")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface Fa0/2")
t.read("my_switch(config-if)#")
t.write("no ip vrf forwarding")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, "Fa0/2", [
"interface FastEthernet0/2",
"end"]) | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_ip_setting_vrf_forwarding_wipes_ip_addresses(self, t):
enable(t)
create_vlan(t, "4000")
create_interface_vlan(t, "4000")
configuring_interface_vlan(t, "4000", do="ip address 10.10.0.10 255.255.255.0")
configuring_interface_vlan(t, "4000", do="ip address 10.10.1.10 255.255.255.0 secondary")
assert_interface_configuration(t, "Vlan4000", [
"interface Vlan4000",
" ip address 10.10.1.10 255.255.255.0 secondary",
" ip address 10.10.0.10 255.255.255.0",
"end"])
configuring_interface_vlan(t, "4000", do="ip vrf forwarding DEFAULT-LAN")
assert_interface_configuration(t, "Vlan4000", [
"interface Vlan4000",
" ip vrf forwarding DEFAULT-LAN",
" no ip address",
"end"])
configuring(t, do="no interface vlan 4000")
remove_vlan(t, "4000") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_ip_helper(self, t):
enable(t)
create_interface_vlan(t, "4000")
assert_interface_configuration(t, "Vlan4000", [
"interface Vlan4000",
" no ip address",
"end"])
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface vlan 4000")
t.read("my_switch(config-if)#")
t.write("ip helper-address")
t.readln("% Incomplete command.")
t.readln("")
t.read("my_switch(config-if)#")
t.write("ip helper-address 1.1.1")
t.readln("% Incomplete command.")
t.readln("")
t.read("my_switch(config-if)#")
t.write("ip helper-address 1.a.1")
t.readln(" ^")
t.readln("% Invalid input detected at '^' marker.") # not incomplete
t.readln("")
t.read("my_switch(config-if)#")
t.write("ip helper-address invalid.ip")
t.readln(" ^")
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch(config-if)#")
t.write("ip helper-address 10.10.0.1 EXTRA INFO")
t.readln(" ^")
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
configuring_interface_vlan(t, "4000", do="ip helper-address 10.10.10.1")
assert_interface_configuration(t, "Vlan4000", [
"interface Vlan4000",
" no ip address",
" ip helper-address 10.10.10.1",
"end"])
configuring_interface_vlan(t, "4000", do="ip helper-address 10.10.10.1")
configuring_interface_vlan(t, "4000", do="ip helper-address 10.10.10.2")
configuring_interface_vlan(t, "4000", do="ip helper-address 10.10.10.3")
assert_interface_configuration(t, "Vlan4000", [
"interface Vlan4000",
" no ip address",
" ip helper-address 10.10.10.1",
" ip helper-address 10.10.10.2",
" ip helper-address 10.10.10.3",
"end"])
configuring_interface_vlan(t, "4000", do="no ip helper-address 10.10.10.1")
assert_interface_configuration(t, "Vlan4000", [
"interface Vlan4000",
" no ip address",
" ip helper-address 10.10.10.2",
" ip helper-address 10.10.10.3",
"end"])
configuring_interface_vlan(t, "4000", do="no ip helper-address 10.10.10.1")
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface vlan 4000")
t.read("my_switch(config-if)#")
t.write("no ip helper-address 10.10.0.1 EXTRA INFO")
t.readln(" ^")
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
configuring_interface_vlan(t, "4000", do="no ip helper-address")
assert_interface_configuration(t, "Vlan4000", [
"interface Vlan4000",
" no ip address",
"end"])
configuring(t, do="no interface vlan 4000") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_ip_route(self, t):
enable(t)
configuring(t, do="ip route 1.1.1.0 255.255.255.0 2.2.2.2")
t.write("show ip route static | inc 2.2.2.2")
t.readln("S 1.1.1.0 [x/y] via 2.2.2.2")
t.read("my_switch#")
t.write("show running | inc 2.2.2.2")
t.readln("ip route 1.1.1.0 255.255.255.0 2.2.2.2")
t.read("my_switch#")
configuring(t, do="no ip route 1.1.1.0 255.255.255.0 2.2.2.2")
t.write("show ip route static")
t.readln("")
t.read("my_switch#")
t.write("exit") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_write_memory(self, t):
enable(t)
t.write("write memory")
t.readln("Building configuration...")
t.readln("OK")
t.read("my_switch#") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_show_version(self, t):
enable(t)
t.write("show version")
t.readln("Cisco IOS Software, C3750 Software (C3750-IPSERVICESK9-M), Version 12.2(58)SE2, RELEASE SOFTWARE (fc1)")
t.readln("Technical Support: http://www.cisco.com/techsupport")
t.readln("Copyright (c) 1986-2011 by Cisco Systems, Inc.")
t.readln("Compiled Thu 21-Jul-11 01:53 by prod_rel_team")
t.readln("")
t.readln("ROM: Bootstrap program is C3750 boot loader")
t.readln("BOOTLDR: C3750 Boot Loader (C3750-HBOOT-M) Version 12.2(44)SE5, RELEASE SOFTWARE (fc1)")
t.readln("")
t.readln("my_switch uptime is 1 year, 18 weeks, 5 days, 1 hour, 11 minutes")
t.readln("System returned to ROM by power-on")
t.readln("System image file is \"flash:c3750-ipservicesk9-mz.122-58.SE2.bin\"")
t.readln("")
t.readln("")
t.readln("This product contains cryptographic features and is subject to United")
t.readln("States and local country laws governing import, export, transfer and")
t.readln("use. Delivery of Cisco cryptographic products does not imply")
t.readln("third-party authority to import, export, distribute or use encryption.")
t.readln("Importers, exporters, distributors and users are responsible for")
t.readln("compliance with U.S. and local country laws. By using this product you")
t.readln("agree to comply with applicable laws and regulations. If you are unable")
t.readln("to comply with U.S. and local laws, return this product immediately.")
t.readln("")
t.readln("A summary of U.S. laws governing Cisco cryptographic products may be found at:")
t.readln("http://www.cisco.com/wwl/export/crypto/tool/stqrg.html")
t.readln("")
t.readln("If you require further assistance please contact us by sending email to")
t.readln("[email protected].")
t.readln("")
t.readln("cisco WS-C3750G-24TS-1U (PowerPC405) processor (revision H0) with 131072K bytes of memory.")
t.readln("Processor board ID FOC1530X2F7")
t.readln("Last reset from power-on")
t.readln("0 Virtual Ethernet interfaces")
t.readln("12 Gigabit Ethernet interfaces")
t.readln("The password-recovery mechanism is enabled.")
t.readln("")
t.readln("512K bytes of flash-simulated non-volatile configuration memory.")
t.readln("Base ethernet MAC Address : 00:00:00:00:00:00")
t.readln("Motherboard assembly number : 73-10219-09")
t.readln("Power supply part number : 341-0098-02")
t.readln("Motherboard serial number : FOC153019Z6")
t.readln("Power supply serial number : ALD153000BB")
t.readln("Model revision number : H0")
t.readln("Motherboard revision number : A0")
t.readln("Model number : WS-C3750G-24TS-S1U")
t.readln("System serial number : FOC1530X2F7")
t.readln("Top Assembly Part Number : 800-26859-03")
t.readln("Top Assembly Revision Number : C0")
t.readln("Version ID : V05")
t.readln("CLEI Code Number : COMB600BRA")
t.readln("Hardware Board Revision Number : 0x09")
t.readln("")
t.readln("")
t.readln("Switch Ports Model SW Version SW Image")
t.readln("------ ----- ----- ---------- ----------")
t.readln("* 1 12 WS-C3750G-24TS-1U 12.2(58)SE2 C3750-IPSERVICESK9-M")
t.readln("")
t.readln("")
t.readln("Configuration register is 0xF")
t.readln("")
t.read("my_switch#") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_reset_port(self, t):
enable(t)
configuring_interface(t, "FastEthernet0/3", do="description shizzle the whizzle and drizzle with lizzle")
configuring_interface(t, "FastEthernet0/3", do="shutdown")
set_interface_on_vlan(t, "FastEthernet0/3", "123")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" description shizzle the whizzle and drizzle with lizzle",
" switchport access vlan 123",
" switchport mode access",
" shutdown",
"end"])
configuring(t, "default interface FastEthernet0/3")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
"end"]) | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_reset_port_invalid_interface_fails(self, t):
enable(t)
configuring_interface(t, "FastEthernet0/3", do="description shizzle the whizzle and drizzle with lizzle")
t.write("conf t")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("default interface WrongInterfaceName0/3")
t.readln("\s*\^", regex=True)
t.readln("% Invalid input detected at '^' marker (not such interface)")
t.readln("")
t.read("my_switch(config)#")
configuring(t, "default interface FastEthernet0/3") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_standby_version(self, t):
enable(t)
create_vlan(t, "2999")
create_interface_vlan(t, "2999")
configuring_interface_vlan(t, "2999", do='standby version 2')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
" standby version 2",
"end"])
configuring_interface_vlan(t, "2999", do='no standby version 2')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring_interface_vlan(t, "2999", do='standby version 2')
configuring_interface_vlan(t, "2999", do='standby version 1')
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
t.write("configure terminal")
t.readln("Enter configuration commands, one per line. End with CNTL/Z.")
t.read("my_switch(config)#")
t.write("interface vlan 2999")
t.read("my_switch(config-if)#")
t.write("standby version")
t.readln("% Incomplete command.")
t.readln("")
t.read("my_switch(config-if)#")
t.write("standby version 3")
t.readln(" ^")
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch(config-if)#")
t.write("standby version 2 2")
t.readln(" ^")
t.readln("% Invalid input detected at '^' marker.")
t.readln("")
t.read("my_switch(config-if)#")
t.write("exit")
t.read("my_switch(config)#")
t.write("exit")
t.read("my_switch#")
assert_interface_configuration(t, "Vlan2999", [
"interface Vlan2999",
" no ip address",
"end"])
configuring(t, do="no interface vlan 2999")
remove_vlan(t, "2999") | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def test_disable_ntp(self, t):
enable(t)
configuring_interface(t, "FastEthernet 0/3", do="ntp disable")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
" ntp disable",
"end"])
configuring_interface(t, "FastEthernet 0/3", do="no ntp disable")
assert_interface_configuration(t, "FastEthernet0/3", [
"interface FastEthernet0/3",
"end"]) | internap/fake-switches | [
53,
37,
53,
11,
1440447597
] |
def init(self, buffer_id, reporting=None, *args, **kwargs):
self.db_name = buffer_id
self.db_path = os.path.join(os.path.abspath(os.path.curdir), self.db_name + ".sq3")
self.db = adbapi.ConnectionPool('sqlite3', self.db_path, check_same_thread=False)
self._pushed_values = 0
self._popped_values = 0
self._latest_timestamp = 0
self._value = None
self._changed = None
self._statlogging = None
def ready(length):
def log_stats():
_log.info("{} : pushed {}, popped {} (latest timestamp: {}) ".format(self.db_name, self._pushed_values, self._popped_values, self._latest_timestamp))
self._statlogging.reset()
self._changed = True # Something has changed, need to check if readable
# install timer to report on pushing/popping
if reporting:
self._statlogging= async.DelayedCall(reporting, log_stats)
self.scheduler_wakeup()
def create(db):
# Create simple queue table. Using TEXT unless there is a reason not to.
db.execute("CREATE TABLE IF NOT EXISTS queue (value BLOB)")
def error(e):
_log.error("Error initializing queue {}: {}".format(self.db_name, e))
q = self.db.runInteraction(create)
q.addCallback(ready)
q.addErrback(error) | EricssonResearch/calvin-base | [
283,
93,
283,
15,
1432032106
] |
def write(self, value):
def error(e):
_log.warning("Error during write: {}".format(e))
done() # Call done to wake scheduler, not sure this is a good idea
def done(unused=None):
self._changed = True # Let can_read know there may be something new to read
self.scheduler_wakeup()
self._pushed_values += len(value)
try:
value = json.dumps(value) # Convert to string for sqlite
except TypeError:
_log.error("Value is not json serializable")
else:
q = self.db.runOperation("INSERT INTO queue (value) VALUES (?)", (value, ))
q.addCallback(done)
q.addErrback(error) | EricssonResearch/calvin-base | [
283,
93,
283,
15,
1432032106
] |
def error(e):
_log.warning("Error during read: {}".format(e))
done() | EricssonResearch/calvin-base | [
283,
93,
283,
15,
1432032106
] |
def pop(db):
limit = 2 # <- Not empirically/theoretically tested
db.execute("SELECT value FROM queue ORDER BY rowid LIMIT (?)", (limit,))
value = db.fetchall() # a list of (value, ) tuples, or None
if value:
# pop values (i.e. delete rows with len(value) lowest row ids)
db.execute("DELETE FROM queue WHERE rowid in (SELECT rowid FROM queue ORDER BY rowid LIMIT (?))",
(len(value),))
return value | EricssonResearch/calvin-base | [
283,
93,
283,
15,
1432032106
] |
def read(self):
value = []
while self._value:
# get an item from list of replies
dbtuple = self._value.pop(0)
# the item is a tuple, get the first value
dbvalue = dbtuple[0]
# convert value from string and return it
try:
value.extend(json.loads(dbvalue))
except ValueError:
_log.error("No value decoded - possibly corrupt file")
self._popped_values += len(value)
return value | EricssonResearch/calvin-base | [
283,
93,
283,
15,
1432032106
] |
def done(response):
# A count response; [(cnt,)]
if response[0][0] == 0:
try:
os.remove(self.db_path)
except:
# Failed for some reason
_log.warning("Could not remove db file {}".format(self._dbpath)) | EricssonResearch/calvin-base | [
283,
93,
283,
15,
1432032106
] |
def batch_norm(inputs, training, data_format, name=''):
"""Performs a batch normalization using a standard set of parameters."""
# We set fused=True for a significant performance boost. See
# https://www.tensorflow.org/performance/performance_guide#common_fused_ops
return tf.compat.v1.layers.batch_normalization(
inputs=inputs,
axis=1 if data_format == 'channels_first' else 3,
momentum=_BATCH_NORM_DECAY,
epsilon=_BATCH_NORM_EPSILON,
center=True,
scale=True,
training=training,
fused=True,
name=name) | google-research/google-research | [
27788,
6881,
27788,
944,
1538678568
] |
def fixed_padding(inputs, kernel_size, data_format):
"""Pads the input along the spatial dimensions independently of input size.
Args:
inputs: A tensor of size [batch, channels, height_in, width_in] or [batch,
height_in, width_in, channels] depending on data_format.
kernel_size: The kernel to be used in the conv2d or max_pool2d operation.
Should be a positive integer.
data_format: The input format ('channels_last' or 'channels_first').
Returns:
A tensor with the same format as the input with the data either intact
(if kernel_size == 1) or padded (if kernel_size > 1).
"""
pad_total = kernel_size - 1
pad_beg = pad_total // 2
pad_end = pad_total - pad_beg
if data_format == 'channels_first':
padded_inputs = tf.pad(
tensor=inputs,
paddings=[[0, 0], [0, 0], [pad_beg, pad_end], [pad_beg, pad_end]])
else:
padded_inputs = tf.pad(
tensor=inputs,
paddings=[[0, 0], [pad_beg, pad_end], [pad_beg, pad_end], [0, 0]])
return padded_inputs | google-research/google-research | [
27788,
6881,
27788,
944,
1538678568
] |
def _building_block_v2(inputs, filters, training, projection_shortcut, strides,
data_format, name):
"""A single block for ResNet v2, without a bottleneck.
Batch normalization then ReLu then convolution as described by:
Identity Mappings in Deep Residual Networks
https://arxiv.org/pdf/1603.05027.pdf
by Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun, Jul 2016.
Args:
inputs: A tensor of size [batch, channels, height_in, width_in] or [batch,
height_in, width_in, channels] depending on data_format.
filters: The number of filters for the convolutions.
training: A Boolean for whether the model is in training or inference mode.
Needed for batch normalization.
projection_shortcut: The function to use for projection shortcuts (typically
a 1x1 convolution when downsampling the input).
strides: The block's stride. If greater than 1, this block will ultimately
downsample the input.
data_format: The input format ('channels_last' or 'channels_first').
name: Block name.
Returns:
The output tensor of the block; shape should match inputs.
"""
shortcut = inputs
first_name = name + 'first'
inputs = batch_norm(
inputs, training, data_format, name=first_name + 'batch_norm')
inputs = tf.nn.relu(inputs, name=first_name + 'relu')
# The projection shortcut should come after the first batch norm and ReLU
# since it performs a 1x1 convolution.
if projection_shortcut is not None:
shortcut = projection_shortcut(inputs, name=first_name + 'proj')
second_name = name + 'second'
inputs = conv2d_fixed_padding(
inputs=inputs,
filters=filters,
kernel_size=3,
strides=strides,
data_format=data_format,
name=second_name + 'input')
inputs = batch_norm(
inputs, training, data_format, name=second_name + 'batch_norm')
inputs = tf.nn.relu(inputs, name=second_name + 'relu')
third_name = name + 'third'
inputs = conv2d_fixed_padding(
inputs=inputs,
filters=filters,
kernel_size=3,
strides=1,
data_format=data_format,
name=third_name + 'input')
return inputs + shortcut | google-research/google-research | [
27788,
6881,
27788,
944,
1538678568
] |
def projection_shortcut(inputs, name):
return conv2d_fixed_padding(
inputs=inputs,
filters=filters_out,
kernel_size=1,
strides=strides,
data_format=data_format,
name=name) | google-research/google-research | [
27788,
6881,
27788,
944,
1538678568
] |
def __init__(self,
resnet_size,
bottleneck,
num_classes,
num_filters,
kernel_size,
conv_stride,
first_pool_size,
first_pool_stride,
block_sizes,
block_strides,
resnet_version=DEFAULT_VERSION,
data_format=None,
dtype=DEFAULT_DTYPE):
"""Creates a model for classifying an image.
Args:
resnet_size: A single integer for the size of the ResNet model.
bottleneck: Use regular blocks or bottleneck blocks.
num_classes: The number of classes used as labels.
num_filters: The number of filters to use for the first block layer of the
model. This number is then doubled for each subsequent block layer.
kernel_size: The kernel size to use for convolution.
conv_stride: stride size for the initial convolutional layer
first_pool_size: Pool size to be used for the first pooling layer. If
none, the first pooling layer is skipped.
first_pool_stride: stride size for the first pooling layer. Not used if
first_pool_size is None.
block_sizes: A list containing n values, where n is the number of sets of
block layers desired. Each value should be the number of blocks in the
i-th set.
block_strides: List of integers representing the desired stride size for
each of the sets of block layers. Should be same length as block_sizes.
resnet_version: Integer representing which version of the ResNet network
to use. See README for details. Valid values: [1, 2]
data_format: Input format ('channels_last', 'channels_first', or None). If
set to None, the format is dependent on whether a GPU is available.
dtype: The TensorFlow dtype to use for calculations. If not specified
tf.float32 is used.
Raises:
ValueError: if invalid version is selected.
"""
self.resnet_size = resnet_size
if not data_format:
data_format = ('channels_first'
if tf.test.is_built_with_cuda() else 'channels_last')
self.resnet_version = resnet_version
if resnet_version not in (1, 2):
raise ValueError(
'Resnet version should be 1 or 2. See README for citations.')
self.bottleneck = bottleneck
self.block_fn = _building_block_v2
if dtype not in ALLOWED_TYPES:
raise ValueError('dtype must be one of: {}'.format(ALLOWED_TYPES))
self.data_format = data_format
self.num_classes = num_classes
self.num_filters = num_filters
self.kernel_size = kernel_size
self.conv_stride = conv_stride
self.first_pool_size = first_pool_size
self.first_pool_stride = first_pool_stride
self.block_sizes = block_sizes
self.block_strides = block_strides
self.dtype = dtype
self.pre_activation = resnet_version == 2 | google-research/google-research | [
27788,
6881,
27788,
944,
1538678568
] |
def _model_variable_scope(self):
"""Returns a variable scope that the model should be created under.
If self.dtype is a castable type, model variable will be created in fp32
then cast to self.dtype before being used.
Returns:
A variable scope for the model.
"""
return tf.compat.v1.variable_scope(
'resnet_model',
custom_getter=self._custom_dtype_getter,
reuse=tf.AUTO_REUSE) | google-research/google-research | [
27788,
6881,
27788,
944,
1538678568
] |
def si_as_number(text):
"""Convert a string containing an SI value to an integer or return an
integer if that is what was passed in."""
if type(text) == int:
return text
if type(text) not in [str, unicode]:
raise ValueError("Source value must be string or integer")
matches = si_regex.search(text.lower(), 0)
if matches is None:
raise ValueError("Invalid SI value '" + text + "'")
number = int(matches.group(1)) if matches.group(2) is None \
else float(matches.group(1))
unit = matches.group(3)
multiplier = 1 if unit is None else si_multipliers.get(unit.lower(), '')
return number * multiplier | mfeit-internet2/pscheduler-dev | [
45,
31,
45,
115,
1452259533
] |
def si_range(value, default_lower=0):
"""Convert a range of SI numbers to a range of integers.
The 'value' is a dict containing members 'lower' and 'upper', each
being an integer or string suitable for si_as_number(). If
'value' is not a dict, it will be passed directly to
si_as_number() and treated as a non-range (see below). If there
is no 'lower' member and 'default_lower' has been provided, that
value will be used for the lower number.
Returns a dict containing memebers 'lower' and 'upper', both
integers. For non-ranges, both will be identical.
Raises ValueError if something doesn't make sense.
"""
if type(value) in [int, str, unicode]:
result = si_as_number(value)
return {"lower": result, "upper": result}
if type(default_lower) != int:
raise ValueError("Default lower value must be integer")
# TODO: Complain about anything else in the input?
result = {}
if "lower" not in value:
# Copy this because altering it would clobber the original (not cool)
vrange = copy.copy(value)
vrange["lower"] = default_lower
value = vrange
for member in ["lower", "upper"]:
try:
result[member] = si_as_number(value[member])
except KeyError:
raise ValueError("Missing '%s' in input" % member)
if result['lower'] > result['upper']:
raise ValueError("Lower value must be less than upper value")
return result | mfeit-internet2/pscheduler-dev | [
45,
31,
45,
115,
1452259533
] |
def get_cache() -> Dict:
return dict() | OpenMined/PySyft | [
8617,
1908,
8617,
143,
1500410476
] |
def solve_ast_type_functions(path: str, lib_ast: globals.Globals) -> KeysView:
root = lib_ast
for path_element in path.split("."):
root = getattr(root, path_element)
return root.attrs.keys() | OpenMined/PySyft | [
8617,
1908,
8617,
143,
1500410476
] |
def solve_real_type_functions(path: str) -> Set[str]:
parts = path.split(".")
klass_name = parts[-1]
# TODO: a better way. Loot at https://github.com/OpenMined/PySyft/issues/5249
# A way to walkaround the problem we can't `import torch.return_types` and
# get it from `sys.modules`.
if parts[-2] == "return_types":
modu = getattr(sys.modules["torch"], "return_types")
else:
modu = sys.modules[".".join(parts[:-1])]
return set(dir(getattr(modu, klass_name))) | OpenMined/PySyft | [
8617,
1908,
8617,
143,
1500410476
] |
def create_union_ast(
lib_ast: globals.Globals, client: TypeAny = None | OpenMined/PySyft | [
8617,
1908,
8617,
143,
1500410476
] |
def generate_func(target_method: str) -> Callable:
def func(self: TypeAny, *args: TypeAny, **kwargs: TypeAny) -> TypeAny:
func = getattr(self, target_method, None)
if func:
return func(*args, **kwargs)
else:
traceback_and_raise(
ValueError(
f"Can't call {target_method} on {klass} with the instance type of {type(self)}"
)
)
return func | OpenMined/PySyft | [
8617,
1908,
8617,
143,
1500410476
] |
def prop_get(self: TypeAny) -> TypeAny:
prop = getattr(self, target_attribute, None)
if prop is not None:
return prop
else:
ValueError(
f"Can't call {target_attribute} on {klass} with the instance type of {type(self)}"
) | OpenMined/PySyft | [
8617,
1908,
8617,
143,
1500410476
] |
def protest (response, message):
response.send_response(200)
response.send_header('Content-type','application/json')
response.end_headers()
response.wfile.write(message) | Comcast/rulio | [
339,
58,
339,
28,
1447456380
] |
def do_GET(self):
protest(self, "You should POST with json.\n")
return | Comcast/rulio | [
339,
58,
339,
28,
1447456380
] |
def create_pipeline(
pipeline_name: str,
pipeline_root: str,
data_path: str,
preprocessing_fn: str,
run_fn: str,
train_args: tfx.proto.TrainArgs,
eval_args: tfx.proto.EvalArgs,
eval_accuracy_threshold: float,
serving_model_dir: str,
schema_path: Optional[str] = None,
metadata_connection_config: Optional[
metadata_store_pb2.ConnectionConfig] = None,
beam_pipeline_args: Optional[List[str]] = None, | tensorflow/tfx | [
1905,
649,
1905,
157,
1549300476
] |
def test_execute_command(self):
self.assertEqual(execute_command(['exit', '2'], shell=True), 2)
self.assertEqual(execute_command('exit 3', shell=True), 3)
if os.name == 'nt':
self.assertEqual(execute_command(['cmd', '/C', 'exit 4'], shell=False), 4)
self.assertEqual(execute_command(['cmd', '/C', 'echo γγ'], shell=False, cmd_encoding='sjis'), 0)
else:
self.assertEqual(execute_command(['/bin/sh', '-c', 'exit 4'], shell=False), 4)
# This code will not pass in non-Japanese Windows OS.
with self.withAssertOutputFile(
os.path.join('tests', 'resources', 'sjis_ja.txt'), expect_file_encoding='sjis',
output_encoding='sjis', variables={'quote': '"' if os.name == 'nt' else ''}, replace_linesep=True
) as out:
execute_command('echo "γγγγγ"', shell=True, cmd_encoding='sjis', stdout=out) | mogproject/mog-commons-python | [
2,
1,
2,
2,
1444292691
] |
def test_execute_command_with_pid(self):
pid_file = os.path.join(tempfile.gettempdir(), 'mog-commons-python-test.pid')
class RunSleep(threading.Thread):
def run(self):
execute_command_with_pid('python -c "import time;time.sleep(2)"', pid_file, shell=True)
th = RunSleep()
th.start()
time.sleep(1)
with open(pid_file, 'r') as f:
pid = int(f.read())
self.assertTrue(pid_exists(pid))
time.sleep(2)
self.assertFalse(pid_exists(pid))
self.assertEqual(execute_command_with_pid(['exit', '2'], None, shell=True), 2) | mogproject/mog-commons-python | [
2,
1,
2,
2,
1444292691
] |
def __init__(self, name):
self._name = name | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def __init__(self, resolver, proxy_type, key):
if proxy_type == "file":
self._method = resolver.get_file_content
elif proxy_type == "param":
self._method = resolver.get_parameter_value
elif proxy_type == "secret":
self._method = resolver.get_secret_value
elif proxy_type == "bucket_file":
self._method = resolver.get_bucket_file
else:
raise ValueError("Unknown proxy type %s", proxy_type)
self._key = key | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def __init__(self, child_proxy):
self._child_proxy = child_proxy | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
def __init__(self, child_proxy):
self._child_proxy = child_proxy | zentralopensource/zentral | [
671,
87,
671,
23,
1445349783
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.