DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a...

74
DevOps with SUSE: How SUSE Manager, SUSE Studio and SUSE Cloud APIs Facilitate Continuous Software Delivery Joachim Werner Senior Product Manager SUSE/[email protected] Wolfgang Engel Engineer SUSE/[email protected]

Transcript of DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a...

Page 1: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

DevOps with SUSE:How SUSE Manager, SUSE Studio and SUSE Cloud APIs Facilitate Continuous Software Delivery

Joachim WernerSenior Product Manager

SUSE/[email protected]

Wolfgang EngelEngineer

SUSE/[email protected]

Page 2: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

2

Page 3: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Why?

Page 4: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

4

Page 5: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

5

Traditional Collaboration

Development

Operations

HW

OS

APP

CODE

Page 6: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

6

Get Together!

Page 7: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

7

The DevOps Way

Development

Operations

HW

OS

APP

CODE

Page 8: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

8

Continues Delivery

Page 9: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

What If You Want To...

Page 10: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

10

Automate repetitive tasks?

Generate customized reports from the data in a system?

Hook systems together that weren't built to work together?

Orchestrate several separate systems or tools?

Write my own UI because I have different needs than what the authors of the tool had in mind?

Page 11: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

11

• Development‒ Ease package creation

‒ Automate tests and code deployment

‒ Control application stack

‒ Metrics

• Operations‒ Automate system installation/creation and configuration

‒ Control systems

‒ Monitoring

Page 12: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

12

Then You Need APIs!

Page 13: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Setting The Stage...

Page 14: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

14

Objectives of This Session:

• Demonstrate the power of using APIs in SUSE's Cloud and Management products in a real-life example

• Provide starting points and hints for your own work with the APIs

Not:

• A ready to run solution (just limited-scope proof of concept)

• Comprehensive API tutorial (just the tip of the iceberg, much more to discover below sea level)

Page 15: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

15

Scenario

• QA environment for testing new builds of a custom RPM package

• Package should be tested

‒ as part of an appliance image

‒ as an RPM maintenance update to a running instance

• Everything should be fully automated from the time a package is checked in to running the tests

Page 16: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

16

Solution Components

Open Build Service‒ Build your RPMs

SUSE Studio™

‒ Build a new appliance image

‒ Deploy it to the Cloud

SUSE® Manager‒ Deploy RPM-based update

‒ Run test suite

SUSE Cloud‒ Run test instances

Page 17: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

17

Open Build Service (OBS)

• OBS builds binary packages for many distributions and platforms

• OBS makes them available for download

Page 18: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

18

SUSE Studio™

+ Simplify Maintenance

+ Simplify Deployments

+ Streamline the OS

SUSE Studio is a collection of tools designed to improve the efficiency of building, managing and maintaining software virtual and cloud applications

Page 19: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

19

SUSE® Manager

Modular Approach

SUSE Manager delivers completelifecycle management for Linuxservers through its management,provisioning, and monitoringmodules

Page 20: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

20

SUSE® Cloud

Private cloudinfrastructure solutionpowered by OpenStack

Integrated platform and tools for hybrid clouds

SUSE Linux Enterprisein public clouds

Page 21: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

21

Optional Components

GIT or Subversion(everybody should be using a version control system)

Jenkins(to orchestrate)

• http://jenkins-ci.org/

• Jenkins is like “cron on steroids” :-)

Page 22: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Getting Prepared...

Page 23: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

23

Prerequisites (1)For replicating the full setup you need:

• Open Build Service‒ available here: www.open-build-service.org/

‒ or on the SUSE Linux Enterprise SDK

• SUSE Studio™

‒ www.suse.com/products/susestudio/

‒ Talk to your sales contact for an evaluation version

• SUSE® Manager‒ www.suse.com/products/suse-manager/

‒ Eval available on the website

• SUSE Cloud‒ www.suse.com/products/suse-cloud/

‒ Eval available on the website

Page 24: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

24

Prerequisites (2)For replicating the full setup you need:

• On the machine or instance the API automation is run:‒ Python (part of SUSE® Linux Enterprise)

‒ the “requests” module for Python:

‒ http://docs.python-requests.org/en/latest/index.html

‒ http://software.opensuse.org/package/python-requests

• Hardware:‒ SUSE Studio™ Onsite needs a dedicated server

‒ The rest can be virtualized

‒ You need a lot of RAM for Studio, Manager, Cloud

‒ The API automation script can be run on anyOS that has Python.

Page 25: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

25

Prerequisites for “just playing”:Some of the components used here are available online ...

• You can use the openSUSE®

instance of theOpen Build Service:

‒ https://build.opensuse.org

• You can use the freeStudio Online:

‒ http://susestudio.com/

Page 26: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

The Script...

Page 27: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

27

Workflow

• Create a project in OBS

• Create a specfile for an RPM and add it to the project

• Build a new version of the RPM

• Update the RPM in SUSE Studio™

• Update the RPM in SUSE® Manager

• Trigger SUSE Studio image rebuild

• Trigger update of package with SUSE Manager

• Webhook to trigger test deployment of cloud image from SUSE Studio

• Use SUSE Manager to trigger test run of “test suite”

Page 28: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

28

Automating an RPM Package QA Environment:

RPM“MyApp”

GIT

1 Check insources

2 Check outsources

3 Rebuild RPM

4

SUSE Studio

Sync repository/upload RPM

5 Rebuild image

6 Redeployimage SUSE Cloud

Instance 1

Instance 2

Instance 1

7 Sync repository

SUSE Manager

8 UpdateRPM

Instance 2

9 Run test

Instance 1

Instance 2

Page 29: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

29

And One RingScript To Rule Them All:

12

3

45

67

89

Page 30: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

30

Integration Via

• Python-based web service process‒ In the presentation we are skipping the “web service” part

‒ Demos are short executable Python scripts

• OBS, Studio, Manager, and Cloud APIs

Page 31: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

31

We Are Going To Use Python Because ...

• xmlrpc support is built in

• http and url handling built in

• OBS client API is usable as aPython module

• optional: python-requests module

The setup can be replicated in other programming languages of your choice, like

‒ Perl

‒ Ruby

‒ Java

Page 32: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Open Build Service

Page 33: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

33

Open Build Service API

• The OBS API is a RESTful API

• Authentication is done by sending aBasic HTTP Authorisation header (every time)

• Documentation:‒ https://api.opensuse.org/apidocs/

(API Reference)

‒ http://en.opensuse.org/images/d/df/Obs-cheat-sheet.pdf(Cheat Sheet for the command line client)

Page 34: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

34

All code examples arein Python 2 syntax!

And remember:In real life you need to do exception

handling and other boring stuff!

Page 35: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

35

A “Hello World!” Example ...Using the hard way: urllib2

#!/usr/bin/env python

import urllib

import urllib2

url = 'https://api.opensuse.org'

user = 'username'

pwd = 'password'

pwdmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()

pwdmgr.add_password(None, url, user, pwd)

authhandler = urllib2.HTTPBasicAuthHandler(pwdmgr)

opener = urllib2.build_opener(authhandler)

urllib2.install_opener(opener)

response = urllib2.urlopen(url + '/about')

print response.read()

Page 36: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

36

The Response ...

<about> <title>Open Build Service API</title> <description>API to the Open Build Service</description> <revision>2.3.0.git201207101028</revision></about>

Page 37: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

37

Now Let's Introduce The“Requests” Module ...

• “HTTP for Humans” (quote from the website)

• ISC License (permissive BSD-style license)

• Very easy to use

• Well documented

Page 38: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

38

Doesn't This Look Much Nicer?

#!/usr/bin/env python

import requests

url = 'https://api.opensuse.org'

user = 'username'

pwd = 'password'

r = requests.get(url + '/about', auth=(user, pwd))

print r.text

Page 39: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

39

Or We Can Use The osc CommandLine Client As A Library

What is osc?‒ A command line client for OBS that you can use with a syntax

just like svn to check out, modify, and commit packages to OBS

‒ But it can also be used to call the api directly!

‒ You can extend osc with your own commands.

‒ And: you can load it as a library from a Python script.

Page 40: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

40

Preparing For Launch ...

zypper in osc

osc

Your user account / password are not configured yet.

You will be asked for them below, and they will be stored in

/home/joe/.oscrc for future use.

Creating osc configuration file /home/joe/.oscrc ...

Username: username

Password: password

Page 41: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

41

Now You Can Use osc Like This:

osc api about

<about>

<title>Open Build Service API</title>

<description> API to the Open Build Service </description>

<revision>2.3.0.git201207101028</revision>

</about>

Page 42: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

42

This is step 3in our workflow

Or From A Python Script,As Promised:

#!/usr/bin/env python

from osc import core, conf

conf.get_config()

url = conf.config['apiurl']

x=core.rebuild(url, 'home:joachimwerner', 'treeline', 'SLE_11_SP2', 'x86_64')

print x

3

Page 43: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

SUSE Studio™

Page 44: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

44

SUSE Studio™ API (1)

Documentation:

• http://en.opensuse.org/openSUSE:SUSE_Studio_API(Background information, examples etc.)

• http://susestudio.com/help/api/v2(API Reference)

Client libraries:

• http://susestudio.com/help/api/libraries_and_clients.html

Page 45: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

45

SUSE Studio™ API (2)

• The SUSE Studio API is a RESTful API

• Authentication is done by sending aBasic HTTP Authorisation header (every time)

• You need to create an API key for that in the web UI (once)

Page 46: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

46

Creating the API Key

Page 47: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Sync The Updated RPM Repository To SUSE Studio™

4

Page 48: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

48

This Is A New API Call!

POST /api/v2/user/repositories/<id>/refresh

• As of today, this is only in SUSE Studio™ Online

• Planned for SUSE Studio Onsite 1.3

• Workaround is to use the API calls for uploading single RPMs

Page 49: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Rebuild The Image5

Page 50: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

50

Trigger The Rebuild:

#!/usr/bin/env python

import requests

url = 'http://susestudio.com/api/v2/'

user = 'username'

pwd = 'api_key'

parameters = {

'appliance_id': '9999999',

'force': 'true',

'image_type': 'vmx'}

r = requests.post(url + 'user/running_builds', params=parameters, auth=(user, pwd))

print r.text

You can look this up in the web UI!

Page 51: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

51

A build id Is Returned:

<build> <id>12345</id></build>

You can use this id to query the build status later ...

Page 52: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Redeploy Image6

Page 53: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

53

Webhooks

Page 54: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

54

Redeploy Image

• We use a webhook for that

• Here is a nice explanation on how to use them:‒ http://susestudio.com/help/api/webhooks.html

• You need your script to either start a web server (easy with Python) or e.g. run in Apache as a CGI script

• When the rebuild in Studio is finished, the webhook gets called

Page 55: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

55

Create a New Image In OpenStack's“Glance” Image Store

Example, using the current (soon to be deprecated) glance command line:

glance image-create --name=#{data[:name] + " " + data[:build][:version]} --is-public=True --disk-format=qcow2 --container-format=bare --copy-from #{data[:build][:download_url]}

Page 56: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

SUSE® Manager

Page 57: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

57

SUSE® Manager API

• The SUSE Manager API uses XML-RPC.

• Authentication is done by requesting a session key with the “auth.login” method call

Documentation:https://www.suse.com/documentation/suse_manager/• API Reference

• Manager Quick Start Guides and reference documentation

Page 58: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

58

Connecting to SUSE® Manager

#!/usr/bin/env python

import xmlrpclib

url = "https://servername/rpc/api"

user = "username"

password = "password"

api = xmlrpclib.Server(url, verbose=0)

session = api.auth.login(user, password)

print api.user.listUsers(session)

Page 59: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

59

What's So Convenient About TheXML-RPC API?

• In Python, Java and other languages there are XML-RPC modules that allow to transparently communicate over the protocol

• Methods are just called like local methods and return Python or Java data structures (e.g. a Python list) that can be used directly

• No need for parsing the response. All XML parsing is done transparently

Page 60: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Sync The Updated RPM RepositoryTo SUSE® Manager

7

Page 61: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Update RPM On Test Instance8

Page 62: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Run Validation Tests9

Page 63: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

SUSE® Cloud

Page 64: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

64

SUSE® Cloud/OpenStack APIs (1)

• The OpenStack APIs are RESTful

• They can use Jason or XML

Documentation:• http://api.openstack.org/

(API Reference)

• http://docs.openstack.org/api/quick-start/content/(API Quick Start Guide)

• http://docs.openstack.org/api/openstack-compute/programmer/content/(Programming OpenStack Compute API with Shell and Python)

• More here:http://wiki.openstack.org/Documentation#OpenStack_APIs

Page 65: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

65

SUSE® Cloud/OpenStack APIs (2)

• Authentication works by requesting a token from the “keystone” authentication service and using that during a session.

• Similar to Kerberos ...

Page 66: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

66

You Can Download An RC File To Configure Your Client For A SUSE® Cloud

Page 67: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

67

Get A Token:Example using curl, for a change. ;-)

curl -X 'POST' -v https://servername:5000/v2.0/tokens -d '{"auth":{"passwordCredentials":{"username": "username", "password":"password"}, "tenantId":"453c05b"}}' -H 'Content-type: application/json'

Page 68: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

68

Keystone Returns A Token InJason Format

Tip:

From Python you can use the“jason” module to easily parseJason responses

Page 69: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

69

List Available Images

curl -H "X-Auth-Token:ed6b342" https://servername:9292/v1/images

Page 70: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Wrapping Up...

Page 71: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Thank you.

71

If you haven't yet, you should really start looking into using our APIs!

Page 72: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Thank you.

72

Send an e-mail to [email protected] with the subject “APIs rock!” to request more information and stay in touch on this topic!

Page 73: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Corporate HeadquartersMaxfeldstrasse 590409 NurembergGermany

+49 911 740 53 0 (Worldwide)www.suse.com

Join us on:www.opensuse.org

73

Page 74: DevOps with SUSE with SUSE: How SUSE Manager, ... • QA environment for testing new builds of a custom ... (API Quick Start Guide)

Unpublished Work of SUSE. All Rights Reserved.This work is an unpublished work and contains confidential, proprietary and trade secret information of SUSE. Access to this work is restricted to SUSE employees who have a need to know to perform tasks within the scope of their assignments. No part of this work may be practiced, performed, copied, distributed, revised, modified, translated, abridged, condensed, expanded, collected, or adapted without the prior written consent of SUSE. Any use or exploitation of this work without authorization could subject the perpetrator to criminal and civil liability.

General DisclaimerThis document is not to be construed as a promise by any participating company to develop, deliver, or market a product. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. SUSE makes no representations or warranties with respect to the contents of this document, and specifically disclaims any express or implied warranties of merchantability or fitness for any particular purpose. The development, release, and timing of features or functionality described for SUSE products remains at the sole discretion of SUSE. Further, SUSE reserves the right to revise this document and to make changes to its content, at any time, without obligation to notify any person or entity of such revisions or changes. All SUSE marks referenced in this presentation are trademarks or registered trademarks of Novell, Inc. in the United States and other countries. All third-party trademarks are the property of their respective owners.