import argparse
from modules.rpcsqa_helper import *
from modules.chef_helper import *
from swift_helper import *

parser = argparse.ArgumentParser()

parser.add_argument('--environment',
                    action="store",
                    dest="environment",
                    required=True,
                    help="Operating System Distribution to build OpenStack on")

# Save the parsed arguments
results = parser.parse_args()
rpcsqa = rpcsqa_helper()
swift = swift_helper()

# Gather all the nodes for the current environment and set variables for
# their current roles
nodes = rpcsqa.cluster_nodes(results.environment)
proxy = []
storage = []

# When we build monster the swift object will keep track of the nodes it is
# given so we dont have to do this, we will just call the nodes
for node in nodes:
    if node['in_use'] is swift.roles['controller']:
        management = node
    elif node['in_use'] is swift.roles['proxy']:
        proxy.append(node)
def main():
    print "Starting up..."
    # Parse arguments from the cmd line
    parser = argparse.ArgumentParser()
    parser.add_argument('--name', action="store", dest="name", required=False,
                        default="autotest",
                        help="Name for the Open Stack chef environment")

    parser.add_argument('--vm', action="store_true", dest="vm",
                        required=False, default=False,
                        help="Use libvirt to test instead of physical??")

    parser.add_argument('--public_cloud', action="store_true",
                        dest="public_cloud", required=False, default=False,
                        help="Use public cloud to test instead of physical??")

    parser.add_argument('--baremetal', action="store_true", dest="baremetal",
                        required=False, default=True,
                        help="Test using baremetal")

    parser.add_argument('--destroy', action="store_true", dest="destroy",
                        required=False, default=False,
                        help="Destroy and only destroy the openstack build?")

    parser.add_argument('--os_distro', action="store", dest="os_distro",
                        required=False, default='precise',
                        help="Operating System Distribution")

    parser.add_argument('--branch', action="store", dest="branch",
                        required=False, default="grizzly",
                        help="The rcbops cookbook branch")

    parser.add_argument('--computes', action="store", dest="computes",
                        required=False, default=1,
                        help="Number of computes.")

    parser.add_argument('--ha', action='store_true', dest='ha',
                        required=False, default=False,
                        help="Do you want to HA this environment?")

    parser.add_argument('--neutron', action='store_true', dest='neutron',
                        required=False, default=False,
                        help="Do you want neutron networking")

    parser.add_argument('--glance', action='store_true', dest='glance',
                        required=False, default=False,
                        help="Do you want glance in cloudfiles")

    parser.add_argument('--openldap', action='store_true', dest='openldap',
                        required=False, default=False,
                        help="Do you want openldap keystone?")

    parser.add_argument('--remote_chef', action="store_true",
                        dest="remote_chef", required=False, default=False,
                        help="Build a new chef server for this deploy")

    parser.add_argument('--log_level', action="store", dest="log_level",
                        default="info", required=False,
                        help="Log level for chef client runs.")

    #Testing
    parser.add_argument('--tempest', action="store_true", dest="tempest",
                        required=False, default=False,
                        help="Run tempest after installing openstack?")

    #Defaulted arguments
    parser.add_argument('--razor_ip', action="store", dest="razor_ip",
                        default="198.101.133.3",
                        help="IP for the Razor server")

    # Save the parsed arguments
    args = parser.parse_args()
    feature_list = ['openldap', 'neutron', 'ha', 'glance']
    features = [x for x in feature_list if args.__dict__[x] is True]
    if features == []:
        features = ['default']
    computes = int(args.computes)

    branch = "grizzly"
    if args.branch in ["4.1.1", "4.1.0"]:
        branch = "folsom"

    # Setup the helper class ( Chef )
    qa = rpcsqa_helper()

    cookbooks = [
        {
            "url": "https://github.com/rcbops/chef-cookbooks.git",
            "branch": args.branch
        }
    ]

    #Prepare environment
    env = qa.prepare_environment(args.name,
                                 args.os_distro,
                                 branch,
                                 features,
                                 args.branch)
    print json.dumps(Environment(env).override_attributes, indent=4)

    #####################
    #   GATHER NODES
    #####################
    if args.vm:
        print "VM's not yet supported..."
        sys.exit(1)

    if args.public_cloud:
        print "Public cloud not yet supported...."
        sys.exit(1)

    if args.baremetal:
        qa.enable_razor(args.razor_ip)
        print "Starting baremetal...."
        print "Removing broker fails"
        qa.remove_broker_fail("qa-%s-pool" % args.os_distro)
        print "Interfacing nodes that need it"
        qa.interface_physical_nodes(args.os_distro)
        try:
            print "Cleaning up old environment (deleting nodes) "
            # Clean up the current running environment (delete old servers)
            qa.cleanup_environment(env)
        except Exception, e:
            print e
            qa.cleanup_environment(env)
            sys.exit(1)


    #####################
    #   BUILD
    #####################

        # These builds would be nice as a class
        build = []
        try:

            if args.openldap:
                node = qa.get_razor_node(args.os_distro, env)
                post_commands = ['ldapadd -x -D "cn=admin,dc=rcb,dc=me" -wostackdemo -f /root/base.ldif',
                                 {'function': qa.update_openldap_environment, 'kwargs': {'env': env}}]
                build.append({'name': node.name,
                              'in_use': 'openldap',
                              'run_list': ['role[qa-openldap-%s]' % args.os_distro],
                              'post_commands': post_commands,
                              'ip': node['ipaddress']
                              })

            if args.remote_chef:
                node = qa.get_razor_node(args.os_distro, env)

                post_commands = [{'function': qa.build_chef_server,
                                  'kwargs': {'cookbooks': cookbooks, 'env': env}}]

                build.append({'name': node.name,
                              'ip': node['ipaddress'],
                              'in_use': 'chef_server',
                              'post_commands': post_commands})

            if args.neutron:
                node = qa.get_razor_node(args.os_distro, env)
                build.append({'name': node.name,
                              'ip': node['ipaddress'],
                              'in_use': 'neutron',
                              'run_list': ['role[single-network-node]']})

            #Controller
            if args.ha:
                pre_commands = [{'function': qa.prepare_cinder, 'kwargs': {'node': node, 'api': api}}]
                node = qa.get_razor_node(args.os_distro, env)
                build.append({'name': node.name,
                              'ip': node['ipaddress'],
                              'in_use': 'ha_controller1',
                              'pre_commands': pre_commands,
                              'run_list': ['role[ha-controller1]', 'role[cinder-all]']})

                node = qa.get_razor_node(args.os_distro, env)
                build.append({'name': node.name,
                              'ip': node['ipaddress'],
                              'in_use': 'ha_controller2',
                              'run_list': ['role[ha-controller2]']})
            else:
                pre_commands = [{'function': qa.prepare_cinder, 'kwargs': {'node': node, 'api': api}}]
                node = qa.get_razor_node(args.os_distro, env)
                build.append({'name': node.name,
                              'ip': node['ipaddress'],
                              'in_use': 'single-controller',
                              'pre_commands': pre_commands,
                              'run_list': ['role[ha-controller1]', 'role[cinder-all]']})


            #Compute with whatever is left
            num_computes = 0
            for n in xrange(computes):
                node = qa.get_razor_node(args.os_distro, env)
                build.append({'name':  node.name,
                              'ip': node['ipaddress'],
                              'in_use': 'single-compute',
                              'run_list': ['role[single-compute]']})
                num_computes += 1

            #If no nodes left, run controller as compute
            if num_computes == 0:
                build[-1]['run_list'] = build[-1]['run_list'] + ['role[single-compute]']


        except IndexError, e:
            print "*** Error: Not enough nodes for your setup"
            qa.cleanup_environment(env)
            qa.delete_environment(env)
            sys.exit(1)
                    help="Name for the chef environment")
parser.add_argument('--feature_set', action="store", dest="feature_set",
                    required=False,
                    help="Name of the feature set")
parser.add_argument('--os_distro', action="store", dest="os_distro",
                    required=False, default='precise',
                    help="Operating System to use")
parser.add_argument('--old_branch', action="store",
                    dest="old_branch", required=False, default="grizzly",
                    help="Use this to upgrade to a specific branch.")
parser.add_argument('--upgrade_branch', action="store",
                    dest="upgrade_branch", required=False, default="v4.1.3rc",
                    help="Use this to upgrade to a specific branch.")
results = parser.parse_args()

rpcsqa = rpcsqa_helper()
env = rpcsqa.cluster_environment(name=results.name,
                                 os_distro=results.os_distro,
                                 branch=results.old_branch,
                                 feature_set=results.feature_set)
remote_chef = rpcsqa.remote_chef_api(env)
pprint(vars(remote_chef))

# Upgrade Process: https://github.com/rcbops/support-tools/blob/master/grizzly-upgrade/README.md
print "##### Updating %s to Grizzly #####" % env.name

print "Uploading grizzly cookbooks and roles to chef server"
query = "chef_environment:%s AND run_list:*network-interfaces*" % env.name
search = rpcsqa.node_search(query=query)
chef_server = next(search)
Beispiel #4
0
def main():
    print "Starting up..."
    # Parse arguments from the cmd line
    parser = argparse.ArgumentParser()
    parser.add_argument('--name',
                        action="store",
                        dest="name",
                        required=False,
                        default="autotest",
                        help="Name for the Open Stack chef environment")

    parser.add_argument('--vm',
                        action="store_true",
                        dest="vm",
                        required=False,
                        default=False,
                        help="Use libvirt to test instead of physical??")

    parser.add_argument('--public_cloud',
                        action="store_true",
                        dest="public_cloud",
                        required=False,
                        default=False,
                        help="Use public cloud to test instead of physical??")

    parser.add_argument('--baremetal',
                        action="store_true",
                        dest="baremetal",
                        required=False,
                        default=True,
                        help="Test using baremetal")

    parser.add_argument('--destroy',
                        action="store_true",
                        dest="destroy",
                        required=False,
                        default=False,
                        help="Destroy and only destroy the openstack build?")

    parser.add_argument('--os_distro',
                        action="store",
                        dest="os_distro",
                        required=False,
                        default='precise',
                        help="Operating System Distribution")

    parser.add_argument('--branch',
                        action="store",
                        dest="branch",
                        required=False,
                        default="grizzly",
                        help="The rcbops cookbook branch")

    parser.add_argument('--computes',
                        action="store",
                        dest="computes",
                        required=False,
                        default=1,
                        help="Number of computes.")

    parser.add_argument('--ha',
                        action='store_true',
                        dest='ha',
                        required=False,
                        default=False,
                        help="Do you want to HA this environment?")

    parser.add_argument('--neutron',
                        action='store_true',
                        dest='neutron',
                        required=False,
                        default=False,
                        help="Do you want neutron networking")

    parser.add_argument('--glance',
                        action='store_true',
                        dest='glance',
                        required=False,
                        default=False,
                        help="Do you want glance in cloudfiles")

    parser.add_argument('--openldap',
                        action='store_true',
                        dest='openldap',
                        required=False,
                        default=False,
                        help="Do you want openldap keystone?")

    parser.add_argument('--remote_chef',
                        action="store_true",
                        dest="remote_chef",
                        required=False,
                        default=False,
                        help="Build a new chef server for this deploy")

    parser.add_argument('--log_level',
                        action="store",
                        dest="log_level",
                        default="info",
                        required=False,
                        help="Log level for chef client runs.")

    #Testing
    parser.add_argument('--tempest',
                        action="store_true",
                        dest="tempest",
                        required=False,
                        default=False,
                        help="Run tempest after installing openstack?")

    #Defaulted arguments
    parser.add_argument('--razor_ip',
                        action="store",
                        dest="razor_ip",
                        default="198.101.133.3",
                        help="IP for the Razor server")

    # Save the parsed arguments
    args = parser.parse_args()
    feature_list = ['openldap', 'neutron', 'ha', 'glance']
    features = [x for x in feature_list if args.__dict__[x] is True]
    if features == []:
        features = ['default']
    computes = int(args.computes)

    branch = "grizzly"
    if args.branch in ["4.1.1", "4.1.0"]:
        branch = "folsom"

    # Setup the helper class ( Chef )
    qa = rpcsqa_helper()

    cookbooks = [{
        "url": "https://github.com/rcbops/chef-cookbooks.git",
        "branch": args.branch
    }]

    #Prepare environment
    env = qa.prepare_environment(args.name, args.os_distro, branch, features,
                                 args.branch)
    print json.dumps(Environment(env).override_attributes, indent=4)

    #####################
    #   GATHER NODES
    #####################
    if args.vm:
        print "VM's not yet supported..."
        sys.exit(1)

    if args.public_cloud:
        print "Public cloud not yet supported...."
        sys.exit(1)

    if args.baremetal:
        qa.enable_razor(args.razor_ip)
        print "Starting baremetal...."
        print "Removing broker fails"
        qa.remove_broker_fail("qa-%s-pool" % args.os_distro)
        print "Interfacing nodes that need it"
        qa.interface_physical_nodes(args.os_distro)
        try:
            print "Cleaning up old environment (deleting nodes) "
            # Clean up the current running environment (delete old servers)
            qa.cleanup_environment(env)
        except Exception, e:
            print e
            qa.cleanup_environment(env)
            sys.exit(1)

    #####################
    #   BUILD
    #####################

    # These builds would be nice as a class
        build = []
        try:

            if args.openldap:
                node = qa.get_razor_node(args.os_distro, env)
                post_commands = [
                    'ldapadd -x -D "cn=admin,dc=rcb,dc=me" -wostackdemo -f /root/base.ldif',
                    {
                        'function': qa.update_openldap_environment,
                        'kwargs': {
                            'env': env
                        }
                    }
                ]
                build.append({
                    'name':
                    node.name,
                    'in_use':
                    'openldap',
                    'run_list': ['role[qa-openldap-%s]' % args.os_distro],
                    'post_commands':
                    post_commands,
                    'ip':
                    node['ipaddress']
                })

            if args.remote_chef:
                node = qa.get_razor_node(args.os_distro, env)

                post_commands = [{
                    'function': qa.build_chef_server,
                    'kwargs': {
                        'cookbooks': cookbooks,
                        'env': env
                    }
                }]

                build.append({
                    'name': node.name,
                    'ip': node['ipaddress'],
                    'in_use': 'chef_server',
                    'post_commands': post_commands
                })

            if args.neutron:
                node = qa.get_razor_node(args.os_distro, env)
                build.append({
                    'name': node.name,
                    'ip': node['ipaddress'],
                    'in_use': 'neutron',
                    'run_list': ['role[single-network-node]']
                })

            #Controller
            if args.ha:
                pre_commands = [{
                    'function': qa.prepare_cinder,
                    'kwargs': {
                        'node': node,
                        'api': api
                    }
                }]
                node = qa.get_razor_node(args.os_distro, env)
                build.append({
                    'name':
                    node.name,
                    'ip':
                    node['ipaddress'],
                    'in_use':
                    'ha_controller1',
                    'pre_commands':
                    pre_commands,
                    'run_list': ['role[ha-controller1]', 'role[cinder-all]']
                })

                node = qa.get_razor_node(args.os_distro, env)
                build.append({
                    'name': node.name,
                    'ip': node['ipaddress'],
                    'in_use': 'ha_controller2',
                    'run_list': ['role[ha-controller2]']
                })
            else:
                pre_commands = [{
                    'function': qa.prepare_cinder,
                    'kwargs': {
                        'node': node,
                        'api': api
                    }
                }]
                node = qa.get_razor_node(args.os_distro, env)
                build.append({
                    'name':
                    node.name,
                    'ip':
                    node['ipaddress'],
                    'in_use':
                    'single-controller',
                    'pre_commands':
                    pre_commands,
                    'run_list': ['role[ha-controller1]', 'role[cinder-all]']
                })

            #Compute with whatever is left
            num_computes = 0
            for n in xrange(computes):
                node = qa.get_razor_node(args.os_distro, env)
                build.append({
                    'name': node.name,
                    'ip': node['ipaddress'],
                    'in_use': 'single-compute',
                    'run_list': ['role[single-compute]']
                })
                num_computes += 1

            #If no nodes left, run controller as compute
            if num_computes == 0:
                build[-1]['run_list'] = build[-1]['run_list'] + [
                    'role[single-compute]'
                ]

        except IndexError, e:
            print "*** Error: Not enough nodes for your setup"
            qa.cleanup_environment(env)
            qa.delete_environment(env)
            sys.exit(1)
                    required=False,
                    default=False,
                    help="Build a new chef server for this deploy")

#Defaulted arguments
parser.add_argument('--razor_ip',
                    action="store",
                    dest="razor_ip",
                    default="198.101.133.3",
                    help="IP for the Razor server")

# Save the parsed arguments
results = parser.parse_args()

# Setup the helper class ( Chef / Razor )
rpcsqa = rpcsqa_helper(results.razor_ip)

# Have to add check for empty string due to Jenkins parameters
if results.repo_tag is not None:
    if results.repo_tag == "None":
        results.repo_tag = None

# Remove broker fails for qa-%os_distro-pool
if results.action == 'build':
    rpcsqa.remove_broker_fail("qa-%s-pool" % results.os_distro)

# Prepare environment
env = rpcsqa.prepare_environment(results.name, results.os_distro,
                                 results.feature_set, results.branch)

if results.os_distro == "centos":
                    help="Action to do for Open Stack (build/destroy/add)")

parser.add_argument('--remote_chef', action="store_true", dest="remote_chef",
                    required=False, default=False,
                    help="Build a new chef server for this deploy")

#Defaulted arguments
parser.add_argument('--razor_ip', action="store", dest="razor_ip",
                    default="198.101.133.3",
                    help="IP for the Razor server")

# Save the parsed arguments
results = parser.parse_args()

# Setup the helper class ( Chef / Razor )
rpcsqa = rpcsqa_helper(results.razor_ip)

# Have to add check for empty string due to Jenkins parameters
if results.repo_tag is not None:
    if results.repo_tag == "None":
        results.repo_tag = None

# Remove broker fails for qa-%os_distro-pool
if results.action == 'build':
    rpcsqa.remove_broker_fail("qa-%s-pool" % results.os_distro)

# Prepare environment
env = rpcsqa.prepare_environment(results.name,
                                 results.os_distro,
                                 results.feature_set,
                                 results.branch)