 So hello welcome my name is Hart Hoover. Thank you for sticking around. I know it's been a three long days of summit So your brains are full and that's cool Glad you're here So I'm no dummy. I've been walking around the summit for a few days just like y'all I have seen the summit talks that you've been going to so I've decided to rename this talk hybrid enterprise devops cloud containers So if you're here for a talk like that awesome I wish I could do that last minute, but the open stack some of people would get probably mad at me for changing up and you would too Right, so it's actually called making test-driven development somewhat bearable on open stack Again like I said, my name is Hart Hoover. I'm a DevOps engineer at rack space. I help customers with Cloudy problems. They want to do DevOps, but don't want to learn DevOps DevOps tools so they pay us money to do that for them Our fancy rack space hashtag is rack stack atl if you want to use that In tweeting about this session if you want to take pictures of slides That's cool. Just make sure to use X pro to Instagram filter to make me look really good and to make the slide look really good Red kind of washes out sometimes. So just a fly eye on that Vision as a company for rack space is to be recognized as one of the world's great service companies, right? To me what this means in the context of DevOps automation and test-driven development is well tested equals good service Customers don't want to pay for something that doesn't work I know saying that at the open stack summit is kind of risky, but I'm gonna go ahead and say it anyway Customers will not pay for something that does not work. So Be sure you test your things Better if you test them in what you want the end result to be rather than Writing code then testing to make sure your code works The former is a lot Harder than the latter anyway Test-driven development traditionally is defined by all these words up here that I took from Wikipedia Essentially, this is red green refactor that you may have heard of you write something it fails. It doesn't work You write code for it At a very minimal Second-grade level to get it to work hackiness. It works awesome. Let's refactor the code to make it work That is fine traditional TDD Currently under fire by a lot in the development community as not relevant anymore Kind of old busted. So today we're gonna talk about some new hotness With regards to TDD even though TDD itself is kind of an older idea By the way side note This is not TDD Also, not DevOps by the way the plan code build test release deploy operations is a Toolchain workflow method to achieve something quote-unquote like DevOps DevOps is more of a cultural movement within your organization or within your team to achieve this workflow in a meaningful Let's depend on each other way, right Adding testing here Makes it a little bit better But just because you add testing there doesn't mean you're doing DevOps, right? DevOps is that cultural thing that I've already discussed So adding testing before you actually code is more along lines of TDD traditionally Testing is a really good idea Find mistakes before they happen right and before they happen meaning in production Finding them in Dave dev or staging Testing is also a good idea because your team will not hate you Other people on your team, especially if you're on a quote-unquote DevOps team where you have ops people working with you If something works fine for you, and you don't test it really it just kind of like cool I think this will work push Ops will hate you And in result the most important the people that pay you money won't hate you or tweet about you horribly The problem with Implementing TDD or just testing in general on any team Basically comes down to a few things a few patterns that I've seen among our customer base when talking to them about Test room and development or even testing just in general real automated testing Some companies have a hero culture The guy or girl who writes unit tests integration tests functional tests end-to-end tests Gets no glory if the app works right, but if the app breaks The opposite guy or girl coming in to fix fix the problem gets all the glory right so We've seen resistance to testing in organizations with a hero hero culture Also seen developers that just don't want to do it It's either either out of laziness or just arrogance like I'm the best. I don't need I don't need testing We're talking about testing testing testing really that was an Allen Iverson reference I know there's not the right crowd for that But I've heard these quotes from customers. I just want to write code for my product. I don't want to write tests Well, it works on my machine with vagrant so we're good No, maybe not I Don't do that. There's a QA team that does that They do the testing. I don't do that Another thing I've seen also big one leadership pressure Your boss saying our dates coming up. Where's my code, right? Or it could be your product manager project managers Scrum leaders agile masters, whatever Saying like we got a ship. We got to go now. Why are you spending time writing tests? That is ridiculous Stop that we have money to make. Let's do this Time is money dev time a lot of money I don't know if y'all saw the hiring sheets out there the boards like full of papers everyone wants to pay devs lots of money so Spending dev time on testing might be seen from leadership as a waste of money in time I'm here to tell you that is not the case I think you should do testing. I think you should do test-driven development I know it's crazy, but I think you should be the solution the change that you want to see in the world, right? Go back to your team and say I think you know, maybe our product should be stable a little bit maybe just a little bit and Put in the time to do some testing it will matter a great deal But there's also another solution so Test-driven development as I said before red green refactor, right? So you write a test first. That's failing And then you fix it Like what if you could just do that all the time? continuously That I think is the new way to do test-driven development, right? Have something running. That's always testing your code and Then write code and it'll just refresh and tell you what you broke So we're going to walk through some of that stuff in a second Some tools of the trade here. We're going to walk through what you're going to need to accomplish this First of all, I'm going to point you to a lot of tools that you're going to want to Google later It's cool. I know you're going to be frantically taking pictures of slides With your ex pro to filter and Instagram But you could just go to heart.io. I have a post up there with all the links I'm going to talk about so you just have to remember this so take a picture of this slide and you'll be good Cool looks like people are doing it awesome sweet Heart.io. It's my name plus I owe at the end kind of easy So the first thing you're going to need Infrastructure to run this test on that's hopefully not your laptop For my purposes since I work at rack space, I'm going to pimp rack space cloud servers Open stack based open stack powered good stuff If you have a private cloud lying around that you can use use that if you have a public cloud somewhere else That's cool, too As long as it's the same hopefully the same infrastructure that you're running for production So you can have the same in type of environment, right that you're using tests as production. It's a good thing You're also going to want. I don't know some source control. That'd probably be a good idea If you are not used is anyone not using source control for their code today Yeah, okay, cool. Good work. We'll skip that one So the rest of my talk is going to be mostly focused around chef and Configuration management. Hopefully you are using a configuration management platform or solution I know that there is a million different apps represented in this room Running all kinds of code. What I do know is that I can talk about the thing Hopefully you're going to use to deploy that code on your infrastructure and how you can do some testing on that There isn't enough time in the session to cover Every testing thing for every language possible So I'm just going to talk about the thing the code that you use to deploy that app Cool. By the way, if you do not have a chef server One will be provided for you as a heat template. We have a heat template on github That you can use against rack spaces orchestration service that Troy talked about in his keynote To deploy a chef server if you don't have one and want to learn chef or want to use chef Spin up a server with chef on it. Awesome First thing you're going to need when Messing with chef at least lately is the chef development kit which you can get here Comes with a bunch of cool tools. They can use to generate cookbooks work with chef work with the chef server like these chef is a command line generator for cookbooks recipes LWRT LWRPs resources files all kinds of stuff Chef client is where the magic actually happens to actually do a chef run Knife is how you interface with your chef server Oh, hi is a service that gathers information about your instances in the cloud and reports it back to you or your chef runs And then chef zero is a chef server that runs entirely a memory All of these things come with the chef development kit as well as my favorite name for a tool ever Berkshelf Berkshelf is so named because It's easy to Google. It's not bookshelf like chef is not easy to Google Google if you try and do that later Berkshelf is pretty easy to Google. It's easy to find Berkshelf is also a cookbook generator It will do dependency resolution for you. It'll manage Pinning your versions of cookbooks, which is super important if you're doing chef Does a whole host of other things. It's great. So Looking at a Berkshelf Configuration file looks like this. Can you see that? Yeah, cool So the first point about this about this Berkshelf is it uses an API to find information about your cookbooks that you're using The metadata flag and a Berkshelf says that this directory that I'm currently in is also a cookbook So you should look at that too Then as far as cookbook specifications, you can specify versions You can also specify if you just want to run master because you're awesome. Yeah, run it master On GitHub you can specify a git repository. It'll just pull that thing down You can also specify a path if you have another cookbook that you're testing locally You want to pull that in you can do that Berkshelf will pull all that stuff together for you in your kitchen in your chef run and I'll demonstrate that in a minute Another awesome tool part of the chef development kit is test kitchen Test kitchen is a tool to execute execute chef code in different virtual machines in isolation from one another Test kitchen is kind of where the magic happens when you want to do a testing chef run Test kitchen you can use open stack as a back-end EC2 You can do Docker Digital ocean all kinds of other vendors as well as rack space and open stack a Test kitchen configuration file is yaml and it looks like this So you're specifying a provisioner here You can say chef solo or you can say chef zero or you can just say chef server and specify other options You tell it what platforms you're going to run on so in this case it'd be a bun 2 1404 You can say about 2204 you can say sent OS. You can say other things There are lots of different platforms out there By default test kitchen uses vagrant as a back-end to build machines locally however here I'm using the Kitchen rack space plug-in, so I'm using a rack space public cloud as my build area So you can specify things like the region you want to build in The server name that you want to use image ID if you have a custom image you want to use what flavor you want to use and Then since we're doing chef. I want the latest and greatest omnibus for chef Then down at the bottom. You can run different testing suites This one is just running the default recipe nothing kind of special there But if you had multiple recipes that you were testing you could run them here and then set custom attributes Also included in the chef development kit. I know there's a lot of stuff included in the chef development kit. You should use it It's awesome Food critic so food critic is a lint tester for cookbooks. It will look at your cookbooks for common mistakes Output a rule number and what you did wrong so you can go in and fix that thing makes cookbooks a lot more shareable a lot more standard as far as cookbooks between groups of people companies etc We'll look at food critic more in a minute chef spec so Like it says up there built on our spec runs chef and memory You can mock data for nodes in service called foe high Chef spec will test things all sorts of stuff. I'll show you an example here There are a ton of examples here and again. That's on that heart.io post This link if you want to look at tons of chef spec examples An example of chef spec here, so you're running chef so saying I want to install a package with that right so I'm going to do that with chef spec and Then either testing whether it installed or whether it did not install, right? We're based on what you're expecting so you either expect it to install properly or you expect like I don't want that package anywhere near me Don't put that on my box So that's about it for the chef development kit But there's some other things that you're going to want to use outside of chef DK which are also great So we're going to cover some honorable mentions that didn't make the list, but are still awesome Server spec is anyone here use server spec today Couple people awesome So server spec also built on our spec, but it uses SSH to actually test your server's actual state So it will look at your server and see what's actually going on Here's some things that you can test with server spec an example of Apache, right? So this package should be installed this service should be running this port should be listening Another thing that I wanted to discuss is me's which is a rack or written tool It is a chef cookbook generator that includes tons of testing tools all the stuff that I've already talked about and then some It Stands for me simple us, which is I probably butchered and I'm sorry cooks or French people out there, but Meese will generate everything you need for a chef cookbook all the testing. It's fantastic. I'm going to show you that in a minute Rubo cop say Ruby it is a hook for the Ruby style guide. So it checks Code layout rejax strings and syntax all sorts of things It will tell you if your code will even work and finally guard guard is Really cool because it will run while you are writing code and run some tests for you Continuously back to that continuous testing stuff So guard will test while you're actually working. So every time you save a file guard will test it Show you if you did something wrong So you can go back and fix it real quick I'll show guard in a second as well kind of showing you kind of an intro to all these things so we can look at them all together at once The cool thing about all these tools that I've mentioned so far is that they are all Ruby Which means you can just include them in a Ruby gem file at once in your directory And your working directory and do bundle install and they'll all download. It's kind of cool But you're probably thinking by now get to the open sack stuff We're at the open sack summit. Why are you talking about chef so much? That's where this stuff comes in at the bottom of the gem file. So test kitchen and then the two plug-ins, right? Kitchen rack space and kitchen open stack I'm going to be using kitchen rack space because I don't have access to a private cloud today But I do have access to a public cloud. So I'm going to be using that so Let's do a demo sound good I'm not going to be a shuttle worth guy and do a crazy demo, but I'll do a demo I'm actually going to demo a chef chef development of My favorite enterprise Java application Minecraft cool. Let's do this So the first thing I wanted to show you guys was me's So let's say you have a cookbook called my app for an application cookbook And you'll see that remember I'm good. Yeah So you just run me's my app. Oh looks like I already did this one. That's okay. Oh Oh, yeah, cool. So If we scroll up a little bit You'll see that it created a cookbook created a read me created a changelog file metadata did a Berkshelf for me Get ignore so it made a get repo vagrant file did some knife stuff rake stuff Added a gem file Super awesome. So at the end and there's my kitchen yaml for test kitchen So and guard whoo, so at the end it just says hey log in do bundle install Let's look at the gem file So here you can say what I was kind of describing earlier We've got Berkshelf up here at the top It's got you know some comments if you want to do that and then all of your gems here with proper versions newer versions Just with one command super easy to get started at least have the testing tools in place to easily take advantage of them So this cookbook is a cookbook Minecraft. It's just straight off github. It is the chef community cookbook for Minecraft Altered by me to break on purpose so I could show you some testing But it actually does work if you just use it So the first thing I want to run is guard so guard says that Based on rubo cop style guide. I've got some problems It looks like I also have a food critic problem So let's take care of those rubo cop ones first Let's see rake file line 34 single quotes Cool one left so guard found a problem with my actual test. It's pretty awesome. So Cool, so I fixed that rubo cop says everything's good. No offense is detected. That's awesome I did have a problem with food critic FC 0 0 7 So I can look on the food critic website FC 0 0 7, what did I do? Ensure recipe dependencies are reflected in cookbook metadata. Oh Okay, so I had something in a recipe that included I See here line 20 Apped app is not in my metadata. That's a problem. So save there Run it all again everything good Maybe Yes, cool. So test success. No more problems So granted I know I just said like don't test code after you've written it but for sake of time That's what I did You can run guard actually while you code it will check things as you save the file and be good to go so last but not least I want to walk through a test kitchen run so I Was worried about internet here at the conference. So I did this at my hotel on Monday I saw some demos fail on Monday. I was worried This will work if you do it on a reliable network So I just straight up recorded this so I will show you how we did this thing So I'm basically running kitchen test on this window and on this one I'm just looking at my cloud servers account at rack space with the nova client Seeing what servers are coming up. What's going on? So I'm using Ubuntu 404 as you can see I start with nothing So that it's gonna take a second to create so here's my server being built by test kitchen Video hasn't frozen. It just takes a sec. Cool. So rack space instance built ready doing things Installing chef for me directly Downloading the chef omnibus installer Transferring files up to my server Complain about SSL and it's testing meh cares about a cell Cool, so it's just saying like here's my run list. We're gonna do some Minecraft stuff update my app repose Install Java again Minecraft open enterprise open JDK application Java things So now it's installing Minecraft Just showing you here on the on the right that Servers active of course because it's interacting with it cool chef client finished so Now that chef is actually run and install all my stuff. I'm going to have it run tests So my tests are very simple in this instance Just for time's sake Just running some server spec tests Uploading my test files. Cool. So Open JDK should be installed. It is my Minecraft port should be listening. It is awesome two examples zero failures and Then it destroys the instance for me. So over here. You can see deleted or deleting and then finally gone Just a couple minutes Running a test like this and automating this test Super helpful. You can also automate this test kitchen test inside guard So every time you make a change it will kick off a kitchen run for you and you're probably thinking. Oh my gosh That will take forever My boss will tell me to go faster and that's probably true, but you can use vagrant intermediary intermediate of actual tests run on the platform that you're going to run your production stuff on So you can use vagrant in between that stuff so As you can see this server was deleted But I did run this on a cloud server before this session So the ultimate test does it run Minecraft? Let's check Really, this is just an excuse for me to play Minecraft during a presentation Don't tell anybody Any rackers in here don't tell anybody And if you have Minecraft on your corporate laptops, I know you do some of you out there Join join the game. It's serious like pull it up. Let's do this play No, so here's the server that we're running against In the cloud deployed with chef, maybe I'm in the dark. Let's try this again. Yeah, I am in the dark. Oh Yeah, it's nighttime. I know right like of course trying to do a demo here Minecraft Cool, so maybe you can see it. Maybe you can't I'm trying to bash stuff in the water Yeah Minecraft building things. So I'm gonna leave this server up for a while So hopefully when you play it'll be daytime and you can have some fun with it That's all I really had Except for more things So if you want to take a picture of this slide you can again that server will be up for a little while You can play Minecraft on the cloud Last but not least the obligatory we're hiring slide, right You can go to record talent comm if you're interested in that We also have a booth out there with lovely recruiters. I would love to talk to you And that's all folks any other questions If you have a question, please use the mic. I'll stay here for a minute Yay, I have a question for your heart Yes, I know my opinion on it, but I'm interested in your opinion one of my co-workers I won't say his name, but it sounds like Sreske Yonez He says that if you spin up a knife cluster, that's actually going to speed up the development of scratch a piece Wow And you know on that Wow There's no such thing as a knife cluster, but thanks for playing I'll I hope that that co-worker isn't actually your boss Any other questions well again, I will leave this up For a little bit longer so you can write down the IP or load it in your Minecraft Let's play together. Let's build something cool What's that? What? Unpossible do it from your hotel. It'll be up for a while. I'm telling you trust me Just don't uh, just don't super hack it. All right. Come on. Don't be that person Cool. Thank you