def run_fufu(self): os.system("cls") self.result_table = [] ''' get ssh connection and reset eth0 ip address ''' self.utils = Utils(self) if self.utils.ssh is None: self.result_table.append(['Connection to the system', 'FAIL']) print("Can't established ssh connection") raw_input('Press Enter for continue...') self.menu() else: self.result_table.append(['Connection to the system', 'PASS']) tests = Tests(self, self.utils) if not tests.check_bands(): self.menu() print('Enable Remote and Modem Communication: {}'.format( self.utils.set_remote_communication(1))) ''' save set files ''' self.utils.send_command('udp_bridge1', 'start') storm = Storm(self) for place, band in enumerate(self.utils.get_bands()): storm.save_setfile(place=place, band=band) self.result_table.append(['Save set file for IDOBR', 'PASS']) self.utils.send_command('udp_bridge1', 'stop') self.utils.set_filters(1) tests.verify_connections() ''' test power ''' tests.test_composite_power() ''' test bands status ''' tests.test_band_status() ''' test sw and patch version ''' tests.test_swv() ''' Set date and time''' tests.set_dateTime() ''' TTF calibration ''' tests.ttf_calibrate() ''' Band mute test ''' tests.mute_test() ''' test alarm ''' tests.test_ext_alarm() ''' gps/gpr test ''' tests.gpr_gps_test() ''' clear log ''' tests.clear_log() self.utils.print_table(['Description', 'Status'], self.result_table) self.utils.ssh.close() raw_input('Press Enter for continue...') self.menu()
def setUp(self): FAKE_SSH_CONFIG = """Host * IdentitiesOnly yes Host netscaler hostname 1.1.1.1 port 3367 """ with open('/tmp/ssh_config', 'w+') as f: f.write(FAKE_SSH_CONFIG) self.storm = Storm('/tmp/ssh_config')
def setUp(self): fake_ssh_config = """Host * IdentitiesOnly yes Host netscaler hostname 1.1.1.1 port 3367 """ with open('/tmp/ssh_config', 'w+') as f: f.write(fake_ssh_config) self.storm = Storm('/tmp/ssh_config')
def __init__(self) -> None: """Initialization method. Raises: NoRuntimeDetectedError: If no `Runtime` could be automatically detected. """ # Create the Logger self.log = logging.getLogger(__name__) runtimes = {} self.inactive_hosts = [] # Iterate over ssh configuration entries and look for valid RemoteRuntimes ssh_util = Storm() self.log.debug( "RuntimeManager starts looking for Runtimes based on ssh configuration." ) for ssh_entry in ssh_util.list_entries(only_servers=True): if ssh_entry["host"] in runtimes: continue if (ssh_entry["host"] == "localhost" and "127.0.0.1" in runtimes) or (ssh_entry["host"] == "127.0.0.1" and "localhost" in runtimes): continue try: self.log.debug( f'RuntimeManager tries to instantiate host {ssh_entry["host"]} as Runtime.' ) runtime = Runtime(ssh_entry["host"]) except InvalidRuntimeError: self.inactive_hosts.append(ssh_entry["host"]) self.log.debug( f'RuntimeManager detected host config for {ssh_entry["host"]}, that could NOT be ' f"instantiated as a valid Runtime.") continue runtimes.update({runtime.host: runtime}) self.log.info(runtime.host + " detected as valid Runtime by the RuntimeManager.") try: self._group = RuntimeGroup(list(runtimes.values())) self.log.info( f"RuntimeManager detected {len(runtimes)} valid Runtime(s).") except ValueError as err: raise NoRuntimesDetectedError(err) self.log.debug("RuntimeManager initialized.")
def add_ssh_host(*, name, host, port, login, password): storm_ = Storm() try: storm_.delete_entry(name) except ValueError: pass storm_.add_entry( name, host, login, port, id_file='', # With these options there will be no stupid interactive # questions on ssh key uploading. custom_options=[ 'StrictHostKeyChecking=no', 'UserKnownHostsFile=/dev/null', ], ) # TODO can be insecure. Copy the password to a local file # with 0600 permissions and use the file with `-f` option. local(f'sshpass -p {password} ssh-copy-id {name}')
def execute_host(args): if not args.subcommand == 'list' and not args.host: puts(red('--host is required')) return ssh_config = Storm() if args.subcommand == 'list': for entry in ssh_config.list_entries(): puts(green(entry['host'])) elif args.subcommand == 'add': result = parse(args.connection_url) puts(result) ssh_config.add_entry(args.host, host=result[1], user=result[0], port=result[2], id_file=args.id_file) for entry in ssh_config.list_entries(): puts(green(entry['host'])) elif args.subcommand == 'delete': ssh_config.delete_entry(args.host) for entry in ssh_config.list_entries(): puts(green(entry['host']))
class StormTests(unittest.TestCase): def setUp(self): FAKE_SSH_CONFIG = """Host * IdentitiesOnly yes Host netscaler hostname 1.1.1.1 port 3367 """ f = open('/tmp/ssh_config', 'w+') f.write(FAKE_SSH_CONFIG) f.close() self.storm = Storm('/tmp/ssh_config') def test_config_load(self): self.assertEqual(len(self.storm.ssh_config.config_data), 2) self.assertEqual( self.storm.ssh_config.config_data[0]["options"]["identitiesonly"], 'yes') def test_config_dump(self): self.storm.ssh_config.write_to_ssh_config() for search_str in ["hostname 1.1.1.1", "Host netscaler", "Host *"]: self.assertEqual(True, search_str in open('/tmp/ssh_config').read()) def test_update_host(self): self.storm.ssh_config.update_host("netscaler", {"hostname": "2.2.2.2"}) self.assertEqual( self.storm.ssh_config.config_data[1]["options"]["hostname"], '2.2.2.2') def test_add_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.assertEqual(len(self.storm.ssh_config.config_data), 3) self.assertEqual( self.storm.ssh_config.config_data[2]["options"]["hostname"], 'google.com') def test_edit_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.storm.edit_entry('google', 'google.com', 'root', '23', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.assertEqual(len(self.storm.ssh_config.config_data), 3) self.assertEqual( self.storm.ssh_config.config_data[2]["options"]["port"], '23') def test_delete_host(self): self.storm.delete_entry('netscaler') for host in self.storm.ssh_config.config_data: self.assertEqual(False, host.get("host") == 'netscaler') def test99_delete_all(self): self.storm.delete_all_entries() self.assertEqual(len(self.storm.ssh_config.config_data), 0) def tearDown(self): os.unlink('/tmp/ssh_config')
options, args = parser.parse_args() if len(sys.argv) == 1: print "Type python %s -h or --help for options help." % sys.argv[0] else: if options.command == "": print "Must given -c option\"s value" else: if options.command == "requireInstall": Infra.install(ClusterOptions(True)) if options.command == "deployAll": cluster_options = ClusterOptions(True) Zookeeper.install(cluster_options) Hadoop.install(cluster_options) Storm.install(cluster_options) Hive.install(cluster_options) HBase.install(cluster_options) if options.command == "startZookeeper": Zookeeper.start(ClusterOptions()) if options.command == "stopZookeeper": Zookeeper.stop(ClusterOptions()) if options.command == "startStorm": Storm.start(ClusterOptions()) if options.command == "initCluster": Hadoop.init(ClusterOptions())
class StormTests(unittest.TestCase): def setUp(self): FAKE_SSH_CONFIG = """Host * IdentitiesOnly yes Host netscaler hostname 1.1.1.1 port 3367 """ with open('/tmp/ssh_config', 'w+') as f: f.write(FAKE_SSH_CONFIG) self.storm = Storm('/tmp/ssh_config') def test_config_load(self): self.assertEqual( self.storm.ssh_config.config_data[1]["options"]["identitiesonly"], 'yes') def test_config_dump(self): self.storm.ssh_config.write_to_ssh_config() for search_str in ("hostname 1.1.1.1", "Host netscaler", "Host *"): with open('/tmp/ssh_config') as fd: self.assertIn(search_str, fd.read()) def test_update_host(self): self.storm.ssh_config.update_host("netscaler", {"hostname": "2.2.2.2"}) self.assertEqual( self.storm.ssh_config.config_data[4]["options"]["hostname"], '2.2.2.2') def test_add_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.add_entry('goog', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'google' or item.get("host") == 'goog': self.assertEqual(item.get("options").get("port"), '22') self.assertEqual( item.get("options").get("identityfile"), '/tmp/tmp.pub') def test_edit_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.storm.edit_entry('google', 'google.com', 'root', '23', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'google': self.assertEqual(item.get("options").get("port"), '23') def test_edit_by_hostname_regexp(self): import re self.storm.add_entry('google-01', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.add_entry('google-02', 'google.com', 'root', '23', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.storm.update_entry('google-[0-2]', port='24', identityfile='/tmp/tmp.pub1') for item in self.storm.ssh_config.config_data: if re.match(r"google*", item.get("host")): self.assertEqual( item.get("options").get("identityfile"), '/tmp/tmp.pub1') self.assertEqual(item.get("options").get("port"), '24') def test_delete_host(self): self.storm.delete_entry('netscaler') for host in self.storm.ssh_config.config_data: self.assertEqual(False, host.get("host") == 'netscaler') def test99_delete_all(self): self.storm.delete_all_entries() self.assertEqual(len(self.storm.ssh_config.config_data), 0) def test_uri_parser(self): user = getpass.getuser() TEST_STRINGS = [('[email protected]:22', ('root', 'emreyilmaz.me', 22)), ('emreyilmaz.me', (user, 'emreyilmaz.me', 22)), ('emreyilmaz.me:22', (user, 'emreyilmaz.me', 22)), ('*****@*****.**', ('root', 'emreyilmaz.me', 22))] for uri in TEST_STRINGS: self.assertEqual(parse(uri[0]), uri[1]) # false strings self.assertRaises(StormInvalidPortError, parse, '[email protected]:string-port') def test_search_host(self): results = self.storm.ssh_config.search_host("netsca") self.assertEqual(len(results), 1) def test_custom_options(self): custom_options = ( "StrictHostKeyChecking=no", "UserKnownHostsFile=/dev/null", ) self.storm.add_entry('host_with_custom_option', 'emre.io', 'emre', 22, None, custom_options=custom_options) self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'host_with_custom_option': self.assertEqual( item.get("options").get("StrictHostKeyChecking"), 'no') self.assertEqual( item.get("options").get("UserKnownHostsFile"), '/dev/null') custom_options = ( "StrictHostKeyChecking=yes", "UserKnownHostsFile=/home/emre/foo", ) self.storm.edit_entry('host_with_custom_option', 'emre.io', 'emre', 22, None, custom_options=custom_options) self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'host_with_custom_option': self.assertEqual( item.get("options").get("StrictHostKeyChecking"), 'yes') self.assertEqual( item.get("options").get("UserKnownHostsFile"), '/home/emre/foo') def tearDown(self): os.unlink('/tmp/ssh_config')
import getpass import collections import six from storm import Storm, __version__ from storm.exceptions import StormValueError from storm.ssh_uri_parser import parse from storm import web as _web from storm.kommandr import * from termcolor import colored storm_ = Storm() default_user = getpass.getuser() def fixed_width(text, size): text_width = len(text) if size > text_width: for _ in range(text_width, size): text += " " return text def get_formatted_message(message, format_type): format_typed = fixed_width(format_type, 8)
class StormTests(unittest.TestCase): def setUp(self): FAKE_SSH_CONFIG = """Host * IdentitiesOnly yes Host netscaler hostname 1.1.1.1 port 3367 """ f = open('/tmp/ssh_config', 'w+') f.write(FAKE_SSH_CONFIG) f.close() self.storm = Storm('/tmp/ssh_config') def test_config_load(self): self.assertEqual(self.storm.ssh_config.config_data[1]["options"]["identitiesonly"], 'yes') def test_config_dump(self): self.storm.ssh_config.write_to_ssh_config() for search_str in ["hostname 1.1.1.1", "Host netscaler", "Host *"]: self.assertEqual(True, search_str in open('/tmp/ssh_config').read()) def test_update_host(self): self.storm.ssh_config.update_host("netscaler", {"hostname": "2.2.2.2"}) self.assertEqual(self.storm.ssh_config.config_data[4]["options"]["hostname"], '2.2.2.2') def test_add_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'google': self.assertEqual(item.get("options").get("port"), '22') self.assertEqual(item.get("options").get("identityfile"), '/tmp/tmp.pub') def test_edit_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.storm.edit_entry('google', 'google.com', 'root', '23', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'google': self.assertEqual(item.get("options").get("port"), '23') def test_delete_host(self): self.storm.delete_entry('netscaler') for host in self.storm.ssh_config.config_data: self.assertEqual(False, host.get("host") == 'netscaler') def test99_delete_all(self): self.storm.delete_all_entries() self.assertEqual(len(self.storm.ssh_config.config_data), 0) def test_uri_parser(self): user = getpass.getuser() TEST_STRINGS = [ ('[email protected]:22', ('root', 'emreyilmaz.me', 22)), ('emreyilmaz.me', (user, 'emreyilmaz.me', 22)), ('emreyilmaz.me:22', (user, 'emreyilmaz.me', 22)), ('*****@*****.**', ('root', 'emreyilmaz.me', 22)) ] for uri in TEST_STRINGS: self.assertEqual(parse(uri[0]), uri[1]) # false strings self.assertRaises(StormInvalidPortError, parse, '[email protected]:string-port') def test_search_host(self): results = self.storm.ssh_config.search_host("netsca") self.assertEqual(len(results), 1) def tearDown(self): os.unlink('/tmp/ssh_config')
import math import numpy as np import pandas as pd import matplotlib as plt from shapely.geometry import Point, Polygon from sklearn.metrics import confusion_matrix from scipy import stats import geopandas as gpd import h5py from storm import Storm from readData import ReadEMData print(Storm(1, [[4, 0, 6, 7, 8, 9]])) print("hello world") #get EM data def extractDataEM(): databaseEM = ReadEMData("data/disastersStats.xlsx", "Feuil2") databaseEM.reformatDates() databaseEM.changeDatesToTimeStep() databaseEM.addYearColumn() return databaseEM, databaseEM.aggregateByDisasterNo() def addYear(year, df, world, databaseEM, dataEM): realDisasters = dataEM[dataEM["year"] == year] path = "./climo_" + str(year) + ".h5" simulatedDisasters = creatStormObjectList(path)
def get_storm(): return Storm()
class IdeaBoard(ScatterPlane): storm = ObjectProperty() storm_widgets = DictProperty() background = ObjectProperty() toolbar = ObjectProperty() selected_widget = ObjectProperty(None) def __init__(self, **kwargs): super(IdeaBoard, self).__init__(**kwargs) self.storm = Storm() # Clock.schedule_once(self.buildstuff) def buildstuff(self, *args): w = self.add_idea() w.text = 'very long text which should span across several lines \ without problems' w2 = self.add_idea(parent=w.idea) w2.text = 'dfgskdfhgjskerugbsliehgjkfdhbgyuserbgljkshdfgiusfgjssdfg text\ containing a very very long word, longer than the maximum length of the widget' w = self.add_idea(title='foo', parent=w2.idea) def add_idea(self, idea=None, parent=None, **kwargs): if idea is None: idea = self.storm.add_idea(parent=parent, **kwargs) idea_widget = BoardViewIdea(idea=idea, board=self) # if parent is None: xx, yy = self.to_local(self.parent.width/2, self.parent.height/2) idea_widget.center = xx, yy # else: # idea_widget.center = parent.center self.add_widget(idea_widget) self.storm_widgets[idea.key] = idea_widget idea_widget.bind(pos=self.background.schedule_redraw) self.select_widget(idea_widget) return idea_widget def add_idea_to_selected(self, idea=None, **kwargs): if self.selected_widget is not None: self.add_idea(parent=self.selected_widget.idea) else: self.add_idea() def get_idea_widget(self, idea): if isinstance(idea, BoardViewIdea): return idea return self.storm_widgets.get(idea.key, None) def on_touch_down(self, touch): if self.toolbar.on_touch_down(touch): return True return super(IdeaBoard, self).on_touch_down(touch) def on_touch_move(self, touch): if self.toolbar.on_touch_move(touch): return True return super(IdeaBoard, self).on_touch_move(touch) def on_touch_up(self, touch): if self.toolbar.on_touch_up(touch): return True return super(IdeaBoard, self).on_touch_up(touch) def select_widget(self, widget): if self.selected_widget is not None: if self.select_widget != widget: self.selected_widget.selected = False self.selected_widget = widget widget.selected = True def zoom_to_widget(self, widget=None): if widget is None: widget = self.selected_widget if widget is None: return print widget, widget.center x, y = widget.to_window(widget.width/2, widget.height/2, initial=False) print x, y x, y = self.to_widget(x, y) print x, y anim = Animation(center_x=self.width-x, center_y=self.height-y, d=0.3, t='in_out_quad') anim.start(self)
class StormTests(unittest.TestCase): def setUp(self): FAKE_SSH_CONFIG = """Host * IdentitiesOnly yes Host netscaler hostname 1.1.1.1 port 3367 """ f = open('/tmp/ssh_config', 'w+') f.write(FAKE_SSH_CONFIG) f.close() self.storm = Storm('/tmp/ssh_config') def test_config_load(self): self.assertEqual( self.storm.ssh_config.config_data[1]["options"]["identitiesonly"], 'yes') def test_config_dump(self): self.storm.ssh_config.write_to_ssh_config() for search_str in ["hostname 1.1.1.1", "Host netscaler", "Host *"]: self.assertEqual(True, search_str in open('/tmp/ssh_config').read()) def test_update_host(self): self.storm.ssh_config.update_host("netscaler", {"hostname": "2.2.2.2"}) self.assertEqual( self.storm.ssh_config.config_data[4]["options"]["hostname"], '2.2.2.2') def test_add_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'google': self.assertEqual(item.get("options").get("port"), '22') self.assertEqual( item.get("options").get("identityfile"), '/tmp/tmp.pub') def test_edit_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.storm.edit_entry('google', 'google.com', 'root', '23', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'google': self.assertEqual(item.get("options").get("port"), '23') def test_delete_host(self): self.storm.delete_entry('netscaler') for host in self.storm.ssh_config.config_data: self.assertEqual(False, host.get("host") == 'netscaler') def test99_delete_all(self): self.storm.delete_all_entries() self.assertEqual(len(self.storm.ssh_config.config_data), 0) def test_uri_parser(self): user = getpass.getuser() TEST_STRINGS = [('[email protected]:22', ('root', 'emreyilmaz.me', 22)), ('emreyilmaz.me', (user, 'emreyilmaz.me', 22)), ('emreyilmaz.me:22', (user, 'emreyilmaz.me', 22)), ('*****@*****.**', ('root', 'emreyilmaz.me', 22))] for uri in TEST_STRINGS: self.assertEqual(parse(uri[0]), uri[1]) # false strings self.assertRaises(StormInvalidPortError, parse, '[email protected]:string-port') def test_search_host(self): results = self.storm.ssh_config.search_host("netsca") self.assertEqual(len(results), 1) def tearDown(self): os.unlink('/tmp/ssh_config')
def get_storm(): return Storm(ssh_config)
def __init__(self, **kwargs): super(IdeaBoard, self).__init__(**kwargs) self.storm = Storm()
class StormTests(unittest.TestCase): def setUp(self): FAKE_SSH_CONFIG = """Host * IdentitiesOnly yes Host netscaler hostname 1.1.1.1 port 3367 """ f = open('/tmp/ssh_config', 'w+') f.write(FAKE_SSH_CONFIG) f.close() self.storm = Storm('/tmp/ssh_config') def test_config_load(self): self.assertEqual(len(self.storm.ssh_config.config_data), 2) self.assertEqual(self.storm.ssh_config.config_data[0]["options"]["identitiesonly"], 'yes') def test_config_dump(self): self.storm.ssh_config.write_to_ssh_config() for search_str in ["hostname 1.1.1.1", "Host netscaler", "Host *"]: self.assertEqual(True, search_str in open('/tmp/ssh_config').read()) def test_update_host(self): self.storm.ssh_config.update_host("netscaler", {"hostname": "2.2.2.2"}) self.assertEqual(self.storm.ssh_config.config_data[1]["options"]["hostname"], '2.2.2.2') def test_add_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.assertEqual(len(self.storm.ssh_config.config_data), 3) self.assertEqual(self.storm.ssh_config.config_data[2]["options"]["hostname"], 'google.com') def test_edit_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.storm.edit_entry('google', 'google.com', 'root', '23', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.assertEqual(len(self.storm.ssh_config.config_data), 3) self.assertEqual(self.storm.ssh_config.config_data[2]["options"]["port"], '23') def test_delete_host(self): self.storm.delete_entry('netscaler') for host in self.storm.ssh_config.config_data: self.assertEqual(False, host.get("host") == 'netscaler') def test99_delete_all(self): self.storm.delete_all_entries() self.assertEqual(len(self.storm.ssh_config.config_data), 0) def tearDown(self): os.unlink('/tmp/ssh_config')
def get_storm_instance(config_file=None): return Storm(config_file)
class StormTests(unittest.TestCase): def setUp(self): FAKE_SSH_CONFIG = """Host * IdentitiesOnly yes Host netscaler hostname 1.1.1.1 port 3367 """ with open('/tmp/ssh_config', 'w+') as f: f.write(FAKE_SSH_CONFIG) self.storm = Storm('/tmp/ssh_config') def test_config_load(self): self.assertEqual(self.storm.ssh_config.config_data[1]["options"]["identitiesonly"], 'yes') def test_config_dump(self): self.storm.ssh_config.write_to_ssh_config() for search_str in ("hostname 1.1.1.1", "Host netscaler", "Host *"): with open('/tmp/ssh_config') as fd: self.assertIn(search_str, fd.read()) def test_update_host(self): self.storm.ssh_config.update_host("netscaler", {"hostname": "2.2.2.2"}) self.assertEqual(self.storm.ssh_config.config_data[4]["options"]["hostname"], '2.2.2.2') def test_add_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.add_entry('goog', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'google' or item.get("host") == 'goog': self.assertEqual(item.get("options").get("port"), '22') self.assertEqual(item.get("options").get("identityfile"), '/tmp/tmp.pub') def test_edit_host(self): self.storm.add_entry('google', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.storm.edit_entry('google', 'google.com', 'root', '23', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'google': self.assertEqual(item.get("options").get("port"), '23') def test_edit_by_hostname_regexp(self): import re self.storm.add_entry('google-01', 'google.com', 'root', '22', '/tmp/tmp.pub') self.storm.add_entry('google-02', 'google.com', 'root', '23', '/tmp/tmp.pub') self.storm.ssh_config.write_to_ssh_config() self.storm.update_entry('google-[0-2]', port='24', identityfile='/tmp/tmp.pub1') for item in self.storm.ssh_config.config_data: if re.match(r"google*", item.get("host")): self.assertEqual(item.get("options").get("identityfile"), '/tmp/tmp.pub1') self.assertEqual(item.get("options").get("port"), '24') def test_delete_host(self): self.storm.delete_entry('netscaler') for host in self.storm.ssh_config.config_data: self.assertEqual(False, host.get("host") == 'netscaler') def test99_delete_all(self): self.storm.delete_all_entries() self.assertEqual(len(self.storm.ssh_config.config_data), 0) def test_uri_parser(self): user = getpass.getuser() TEST_STRINGS = [ ('[email protected]:22', ('root', 'emreyilmaz.me', 22)), ('emreyilmaz.me', (user, 'emreyilmaz.me', 22)), ('emreyilmaz.me:22', (user, 'emreyilmaz.me', 22)), ('*****@*****.**', ('root', 'emreyilmaz.me', 22)) ] for uri in TEST_STRINGS: self.assertEqual(parse(uri[0]), uri[1]) # false strings self.assertRaises(StormInvalidPortError, parse, '[email protected]:string-port') def test_search_host(self): results = self.storm.ssh_config.search_host("netsca") self.assertEqual(len(results), 1) def test_custom_options(self): custom_options = ( "StrictHostKeyChecking=no", "UserKnownHostsFile=/dev/null", ) self.storm.add_entry('host_with_custom_option', 'emre.io', 'emre', 22, None, custom_options=custom_options) self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'host_with_custom_option': self.assertEqual(item.get("options").get("StrictHostKeyChecking"), 'no') self.assertEqual(item.get("options").get("UserKnownHostsFile"), '/dev/null') custom_options = ( "StrictHostKeyChecking=yes", "UserKnownHostsFile=/home/emre/foo", ) self.storm.edit_entry('host_with_custom_option', 'emre.io', 'emre', 22, None, custom_options=custom_options) self.storm.ssh_config.write_to_ssh_config() for item in self.storm.ssh_config.config_data: if item.get("host") == 'host_with_custom_option': self.assertEqual(item.get("options").get("StrictHostKeyChecking"), 'yes') self.assertEqual(item.get("options").get("UserKnownHostsFile"), '/home/emre/foo') def tearDown(self): os.unlink('/tmp/ssh_config')