Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(
        epilog=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('address',
                        help='hostname or ip address of target appliance')

    args = parser.parse_args()

    ssh_kwargs = {
        'username': credentials['ssh']['username'],
        'password': credentials['ssh']['password'],
        'hostname': args.address
    }

    # Init SSH client
    with SSHClient(**ssh_kwargs) as ssh_client:

        snmp_path = scripts_data_path.join("snmp")

        # Copy
        print("Copying files")
        ssh_client.put_file(
            snmp_path.join("snmp_listen.rb").strpath, "/root/snmp_listen.rb")
        ssh_client.put_file(
            snmp_path.join("snmp_listen.sh").strpath, "/root/snmp_listen.sh")

        # Enable after startup
        print("Enabling after startup")
        result = ssh_client.run_command(
            "grep 'snmp_listen[.]sh' /etc/rc.local")
        if result.failed:
            ssh_client.run_command(
                "echo 'cd /root/ && ./snmp_listen.sh start' >> /etc/rc.local")
        assert ssh_client.run_command("grep 'snmp_listen[.]sh' /etc/rc.local"
                                      ).success, ("Could not enable!")

        # Run!
        print("Starting listener")
        assert ssh_client.run_command("cd /root/ && ./snmp_listen.sh start"
                                      ).success, ("Could not start!")

        # Open the port if not opened
        print("Opening the port in iptables")
        result = ssh_client.run_command(
            "grep '--dport 8765' /etc/sysconfig/iptables")
        if result.failed:
            # append after the 5432 entry
            ssh_client.run_command(
                "sed -i '/--dport 5432/a -A INPUT -p tcp -m tcp --dport 8765 -j ACCEPT' "
                "/etc/sysconfig/iptables")
            ssh_client.run_command("systemctl restart iptables")
            # last ssh command, close
            # Check if accessible
            try:
                requests.get("http://{}:8765/".format(args.address))
            except requests.exceptions.ConnectionError:
                print("Could not detect running listener!")
                exit(2)
def main():
    parser = argparse.ArgumentParser(epilog=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('address', help='hostname or ip address of target appliance')

    args = parser.parse_args()

    ssh_kwargs = {
        'username': credentials['ssh']['username'],
        'password': credentials['ssh']['password'],
        'hostname': args.address
    }

    # Init SSH client
    with SSHClient(**ssh_kwargs) as ssh_client:

        snmp_path = scripts_data_path.join("snmp")

        # Copy
        print("Copying files")
        ssh_client.put_file(snmp_path.join("snmp_listen.rb").strpath, "/root/snmp_listen.rb")
        ssh_client.put_file(snmp_path.join("snmp_listen.sh").strpath, "/root/snmp_listen.sh")

        # Enable after startup
        print("Enabling after startup")
        result = ssh_client.run_command("grep 'snmp_listen[.]sh' /etc/rc.local")
        if result.failed:
            ssh_client.run_command("echo 'cd /root/ && ./snmp_listen.sh start' >> /etc/rc.local")
        assert ssh_client.run_command("grep 'snmp_listen[.]sh' /etc/rc.local").success, (
            "Could not enable!")

        # Run!
        print("Starting listener")
        assert ssh_client.run_command("cd /root/ && ./snmp_listen.sh start").success, (
            "Could not start!")

        # Open the port if not opened
        print("Opening the port in iptables")
        result = ssh_client.run_command("grep '--dport 8765' /etc/sysconfig/iptables")
        if result.failed:
            # append after the 5432 entry
            ssh_client.run_command(
                "sed -i '/--dport 5432/a -A INPUT -p tcp -m tcp --dport 8765 -j ACCEPT' "
                "/etc/sysconfig/iptables"
            )
            ssh_client.run_command("systemctl restart iptables")
            # last ssh command, close
            # Check if accessible
            try:
                requests.get("http://{}:8765/".format(args.address))
            except requests.exceptions.ConnectionError:
                print("Could not detect running listener!")
                exit(2)
Exemplo n.º 3
0
from cfme.utils import conf, version
from cfme.utils.log import create_sublogger
from cfme.utils.path import conf_path, log_path, scripts_data_path
from cfme.utils.quote import quote
from cfme.utils.wait import wait_for, TimedOutError

# paths to all of the coverage-related files

# on the appliance
#: Corresponds to Rails.root in the rails env
rails_root = local('/var/www/miq/vmdb')
#: coverage root, should match what's in the coverage hook and merger scripts
appliance_coverage_root = rails_root.join('coverage')

# local
coverage_data = scripts_data_path.join('coverage')
gemfile = coverage_data.join('coverage_gem.rb')
bundler_d = rails_root.join('bundler.d')
coverage_hook_file_name = 'coverage_hook.rb'
coverage_hook = coverage_data.join(coverage_hook_file_name)
coverage_merger = coverage_data.join('coverage_merger.rb')
coverage_output_dir = log_path.join('coverage')
coverage_results_archive = coverage_output_dir.join('coverage-results.tgz')
coverage_appliance_conf = conf_path.join('.ui-coverage')

# This is set in sessionfinish, and should be reliably readable
# in post-yield sessionfinish hook wrappers and all hooks thereafter
ui_coverage_percent = None


def clean_coverage_dir():
Exemplo n.º 4
0
from cfme.utils.path import scripts_data_path
from cfme.utils.quote import quote
from cfme.utils.version import LATEST
from cfme.utils.version import LOWEST
from cfme.utils.version import VersionPicker

# paths to all of the coverage-related files

# on the appliance
#: Corresponds to Rails.root in the rails env
rails_root = local('/var/www/miq/vmdb')
#: coverage root, should match what's in the coverage hook and merger scripts
appliance_coverage_root = rails_root.join('coverage')

# local
coverage_data = scripts_data_path.join('coverage')
gemfile = coverage_data.join('coverage_gem.rb')
bundler_d = rails_root.join('bundler.d')
coverage_hook_file_name = 'coverage_hook.rb'
coverage_hook = coverage_data.join(coverage_hook_file_name)
coverage_merger = coverage_data.join('coverage_merger.rb')
coverage_output_dir = log_path.join('coverage')
coverage_results_archive = coverage_output_dir.join('coverage-results.tgz')
coverage_appliance_conf = conf_path.join('.ui-coverage')

# This is set in sessionfinish, and should be reliably readable
# in post-yield sessionfinish hook wrappers and all hooks thereafter
ui_coverage_percent = None


def clean_coverage_dir():