Last active
          October 24, 2016 11:13 
        
      - 
      
- 
        Save gnuoy/10d7bfba699cb6e3f77979cc3429c8f1 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | https://asciinema.org/a/3u30bwy7eq35h6bap1dol4okc | |
| ###################### | |
| # 0) Setup Environment | |
| ###################### | |
| # This should have be done as part of steps 0-2 in the previous demo | |
| # If you are familiar with building a charm that uses the Reactive frame work | |
| # with OpenStack layers and would like to skip those steps | |
| # please jump to 4c | |
| ############################# | |
| # 1) Setup env to write charm | |
| ############################# | |
| # Connect to the ubuntu machine from the previous demo | |
| # ON YOUR LAPTOP: | |
| juju ssh ubuntu/0 | |
| # Install packages needed for charm building | |
| sudo apt-get install --yes charm-tools python-jinja2 | |
| # Create an area to store the congress charm | |
| mkdir ~/congress-charm | |
| cd ~/congress-charm | |
| # Install the Openstack Charm templates | |
| git clone https://github.com/openstack-charmers/charm-templates-openstack | |
| cd charm-templates-openstack | |
| sudo ./setup.py install | |
| ###################################### | |
| # 2) Create source charm from template | |
| ###################################### | |
| # Charm tools provides a utility for building an initial charm from a template. | |
| # The charm can be thought of as the top layer, the OpenStack layers sit beneath | |
| # it and the reactive base layer is at the bottom. | |
| # During the charm generation charm tools asks a few questions about the charm. | |
| # The answers are based on the Congress docs | |
| # http://docs.openstack.org/developer/congress/README.html#separate-install | |
| # ON ubuntu/0 | |
| cd ~/congress-charm | |
| charm-create -t openstack-api congress | |
| What port does the primary service listen on ? 1789 | |
| What is the name of the api service? congress-server | |
| What type of service is this (used for keystone registration)? congress | |
| What is the earliest OpenStack release this charm is compatable with? mitaka | |
| Where command is used to sync the database? congress-db-manage --config-file /etc/congress/congress.conf upgrade head | |
| What packages should this charm install (space seperated list)? congress-server congress-common python-antlr3 python-pymysql | |
| List of config files managed by this charm (space seperated) /etc/congress/congress.conf | |
| What is the name of the init script which controls the primary service congress-server | |
| # Raw answers: | |
| # 1789 | |
| # congress-server | |
| # congress | |
| # mitaka | |
| # congress-db-manage --config-file /etc/congress/congress.conf upgrade head | |
| # congress-server congress-common python-antlr3 python-pymysql | |
| # /etc/congress/congress.conf | |
| # congress-server | |
| # The charm code searches through the templates directories looking for a | |
| # directory corresponding to the OpenStack release being installed or earlier. | |
| # Since Mitaka is the earliest release the charm is supporting a directory called | |
| # mitaka will house the templates and files. | |
| # A template for congress.conf is needed which will have have connection | |
| # information for MySQL and Keystone as well as user controllable config options. | |
| cat <<EOF > ~/congress-charm/congress/src/templates/mitaka/congress.conf | |
| [DEFAULT] | |
| bind_host = {{ options.service_listen_info.congress_server.ip }} | |
| bind_port = {{ options.service_listen_info.congress_server.port }} | |
| auth_strategy = keystone | |
| drivers = congress.datasources.neutronv2_driver.NeutronV2Driver,congress.datasources.glancev2_driver.GlanceV2Driver,congress.datasources.nova_driver.NovaDriver,congress.datasources.keystone_driver.KeystoneDriver,congress.datasources.ceilometer_driver.CeilometerDriver,congress.datasources.cinder_driver.CinderDriver,congress.datasources.swift_driver.SwiftDriver,congress.datasources.plexxi_driver.PlexxiDriver,congress.datasources.vCenter_driver.VCenterDriver,congress.datasources.murano_driver.MuranoDriver,congress.datasources.ironic_driver.IronicDriver | |
| [database] | |
| connection = {{ shared_db.uri }} | |
| {% include "parts/section-keystone-authtoken" %} | |
| EOF | |
| # Unlike most OpenStack API charms, congress does not require a RabbitMQ | |
| # relation. So these steps remove it as a dependancy | |
| sed -i '/amqp/d' ~/congress-charm/congress/src/reactive/congress_handlers.py | |
| sed -i -e "s/ 'amqp',//" ~/congress-charm/congress/src/lib/charm/openstack/congress.py | |
| # For the sake of this demo the deployment is being done on AWS, for the | |
| # specific case code needs to be added to expose the port congress listens on: | |
| cat <<-EOF >> ~/congress-charm/congress/src/reactive/congress_handlers.py | |
| import charmhelpers.core.hookenv as hookenv | |
| @reactive.when('config.rendered') | |
| def expose_congress(): | |
| hookenv.open_port(1789) | |
| EOF | |
| #################### | |
| # 3) Build the charm | |
| #################### | |
| # The charm now needs to be built to pull down all the interfaces and layers the | |
| # charm depends on and rolled into the built charm which can be deployed. | |
| # ON ubuntu/0 | |
| cd ~/congress-charm/congress | |
| charm build -o build src | |
| ##################### | |
| # 4) Deploy the charm | |
| ##################### | |
| # The easiest step is to then push the charm to your namespace on Launchpad. | |
| # If you have an LP account follow 4a else follow 4b. | |
| # (Please only do one of 4a, 4b or 4c) | |
| ########################### | |
| # 4a) Using the charm store | |
| ########################### | |
| # On ubuntu/0 | |
| cd /home/ubuntu/congress-charm/congress/build/builds | |
| charm push . cs:~<lp-usrname>/xenial/congress | |
| charm grant cs:~<lp-usrname>/xenial/congress everyone | |
| # ON YOUR LAPTOP: | |
| juju deploy cs:~<lp-usrname>/xenial/congress | |
| ############################### | |
| # 4b) deploying from local copy | |
| ############################### | |
| # If you don't have access to a launchpad account then pull the charm down to | |
| # the deployment server. | |
| # On ubuntu/0 | |
| cd /home/ubuntu/congress-charm/congress/build/builds | |
| tar zcf /tmp/congress-charm.tgz congress | |
| # ON YOUR LAPTOP: | |
| juju scp ubuntu/0:/tmp/congress-charm.tgz ~/ | |
| cd ~ | |
| tar zxf congress-charm.tgz | |
| juju deploy --series xenial ~/congress | |
| ############################### | |
| # 4c) Deploying pre-build copy | |
| ############################### | |
| # ON YOUR LAPTOP: | |
| juju deploy cs:~gnuoy/xenial/congress-0 | |
| ######################## | |
| # 5) Add charm relations | |
| ######################## | |
| # ON YOUR LAPTOP: | |
| # Now add the relations congress needs to function | |
| juju add-relation congress keystone | |
| juju add-relation congress mysql | |
| juju expose congress | |
| ######################### | |
| # 6) Test Congress Client | |
| ######################### | |
| # Install client and check congress | |
| # On ubuntu/0 | |
| sudo apt install --yes python3-openstackclient python3-congressclient | |
| source ~/novarc | |
| openstack congress policy list | |
| ############### | |
| # 7) Debug Mode | |
| ############### | |
| # Try adding some bespoke config options | |
| # On deployment server: | |
| # ON YOUR LAPTOP: | |
| juju debug-hooks congress/0 | |
| # Another session On deployment server: | |
| # ON YOUR LAPTOP: | |
| juju config congress debug=true | |
| ########################## | |
| # 8) Enable 'debug' option | |
| ########################## | |
| # Back in the debug-hooks session | |
| # There is no debug option in the installed congress.conf | |
| # IN DEBUG_HOOKS SESSION ON congress/0 | |
| grep debug /etc/congress/congress.conf | |
| # so although we have set the debug=true via juju for the congress application | |
| # no change is going to be made. The debug option needs to be added to the | |
| # template. | |
| # Any config option exposed in the config.yaml can be accessed in the template | |
| # in the 'options' namespeace. | |
| # Edit templates/mitaka/congress.conf and add the following line in | |
| # the [DEFAULT] section | |
| debug = {{ options.debug }} | |
| # And run the config-changed hook | |
| ./hooks/config-changed | |
| grep debug /etc/congress/congress.conf | |
| # Looking in the log shows the congress server was restarted to pickup the | |
| # change to the config file | |
| grep Starting /var/log/congress/congress-server.log | tail -5 | |
| ###################################### | |
| # 9) Access values from related charms | |
| ###################################### | |
| # The congress charm is related to keystone and keystone passes over a lot of | |
| # config in its relation. The the keystone interface class (see | |
| # hooks/relations/keystone/requires.py) then passes that to the charm and is | |
| # available in the charms in the identity_service namespace. | |
| # Perhaps congress needs to specify keystone api version | |
| # Edit Template: | |
| # IN DEBUG_HOOKS SESSION ON congress/0 | |
| echo "#Comment: api_version {{ identity_service.api_version }}" >> templates/mitaka/congress.conf | |
| # And run the config-changed hook | |
| ./hooks/config-changed | |
| grep api_version /etc/congress/congress.conf | |
| ######################################### | |
| # 10) New variable based on relation data | |
| ######################################### | |
| # To be able to set a property based on the settings retrieved from an interface. | |
| # In the example below the charm sets a pipeline based on the Keystone API | |
| # version advertised by the keystone interface, | |
| # IN DEBUG_HOOKS SESSION ON congress/0 | |
| # Edit lib/charm/openstack/congress.py | |
| # Add the code below | |
| cat <<EOF >> lib/charm/openstack/congress.py | |
| @charms_openstack.adapters.adapter_property('identity_service') | |
| def charm_pipeline(keystone): | |
| return { | |
| "2": "cors keystone_authtoken context apiapp", | |
| "3": "cors keystone_v3_authtoken context apiapp", | |
| "none": "cors unauthenticated-context apiapp" | |
| }[keystone.api_version] | |
| EOF | |
| # Edit templates/mitaka/congress.conf and add the following comment | |
| echo "# Comment: charm_pipeline {{ identity_service.charm_pipeline }}" >> templates/mitaka/congress.conf | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment