Cookbook->Recipe in install_cookbook,changed format recipe

Right format: cookbook::recipe@0.2.12
This commit is contained in:
Mike Scherbakov 2012-06-07 00:08:42 +04:00
parent 1ba30587e5
commit 18c7a1c843
4 changed files with 35 additions and 33 deletions

View File

@ -26,20 +26,20 @@ def create_cookbook(metafile)
Dir.chdir(recipes_dir)
recipes = Dir.glob("*.rb").map {|x| File.basename(x, '.rb') }
cooks_url = "#{ADMIN_URL}/cookbooks"
cook_data = {'name' => cook_name, 'version' => md.version,
'recipes' => recipes }
recipes_url = "#{ADMIN_URL}/recipes"
headers = {"Content-Type" => "application/json"}
cli = HTTPClient.new
begin
res = cli.post(cooks_url, cook_data.to_json, headers)
if res.status < 200 or res.status >= 300
puts "Error uploading cookbook metadata: #{res.inspect}"
else
puts "Cookbook '#{cook_name}' uploaded."
recipes.each do |recipe|
recipe_full = "#{cook_name}::#{recipe}@#{md.version}"
res = cli.post(recipes_url, {'recipe' => recipe_full}.to_json, headers)
if res.status < 200 or res.status >= 300
puts "Error uploading cookbook metadata: #{res.inspect}"
else
puts "Recipe '#{recipe_full}' created."
end
end
rescue Exception => e
puts "Unknown error: #{e.message}"

View File

@ -1,4 +1,5 @@
import re
import simplejson as json
from django.core.exceptions import ValidationError
from django import forms
@ -16,9 +17,10 @@ class RecipeForm(forms.ModelForm):
def validate_role_recipes(value):
if value and isinstance(value, list):
if not any([re.match(r'\w+@[\w\.]+::\w+', i) for i in value]):
if not any([re.match(r'^[^\]]+::([^\]]+)@[0-9]+(\.[0-9]+){1,2}$', i) \
for i in value]):
raise ValidationError('Recipe should be in \
cookbook@version::recipe format')
cookbook::recipe@version format')
for i in value:
try:
rec_exist = Recipe.objects.get(recipe=i)
@ -65,9 +67,10 @@ def validate_release_node_roles(data):
raise ValidationError('Role name is empty')
for role in data:
for recipe in role['recipes']:
if not re.match(r'\w+@[\w\.]+::\w+', recipe):
if not re.match(r'^[^\]]+::([^\]]+)@[0-9]+(\.[0-9]+){1,2}$', \
recipe):
raise ValidationError('Recipe should be in a \
cook_name@cook_version::recipe_name format')
cook_name::recipe_name@cook_version format')
try:
rec_exists = Recipe.objects.get(recipe=recipe)
except Recipe.DoesNotExist:

View File

@ -29,13 +29,13 @@ class TestHandlers(TestCase):
self.node.save()
self.recipe = Recipe()
self.recipe.recipe = 'cookbook@version::recipe'
self.recipe.recipe = 'cookbook::recipe@2.1'
self.recipe.save()
self.second_recipe = Recipe()
self.second_recipe.recipe = 'nova@0.1.0::compute'
self.second_recipe.recipe = 'nova::compute@0.1.0'
self.second_recipe.save()
self.third_recipe = Recipe()
self.third_recipe.recipe = 'nova@0.1.0::monitor'
self.third_recipe.recipe = 'nova::monitor@0.1.0'
self.third_recipe.save()
self.role = Role()
@ -162,7 +162,6 @@ class TestHandlers(TestCase):
resp = self.client.put(self.node_url,
json.dumps({'metadata': self.new_meta}),
"application/json")
print resp.content
self.assertEquals(resp.status_code, 200)
nodes_from_db = Node.objects.filter(id=self.node.id)
@ -261,7 +260,7 @@ class TestHandlers(TestCase):
self.assertEquals(nodes_from_db[0].metadata, self.old_meta)
def test_recipe_create(self):
recipe = 'cookbook@0.1.0::recipe'
recipe = 'cookbook::recipe@0.1.0'
resp = self.client.post(
reverse('recipe_collection_handler'),
json.dumps({
@ -277,8 +276,8 @@ class TestHandlers(TestCase):
def test_role_create(self):
role_name = 'My role 3'
role_recipes = [
'nova@0.1.0::compute',
'nova@0.1.0::monitor'
'nova::compute@0.1.0',
'nova::monitor@0.1.0'
]
resp = self.client.post(
reverse('role_collection_handler'),
@ -313,8 +312,8 @@ class TestHandlers(TestCase):
def test_release_create(self):
role_name = 'Compute role'
role_recipes = [
'nova@0.1.0::compute',
'cookbook@version::recipe'
'nova::compute@0.1.0',
'cookbook::recipe@2.1'
]
resp = self.client.post(
reverse('role_collection_handler'),
@ -327,7 +326,7 @@ class TestHandlers(TestCase):
self.assertEquals(resp.status_code, 200)
role_name = 'Monitor role'
role_recipes = [
'nova@0.1.0::monitor'
'nova::monitor@0.1.0'
]
resp = self.client.post(
reverse('role_collection_handler'),
@ -345,13 +344,13 @@ class TestHandlers(TestCase):
release_roles = [{
"name": "compute",
"recipes": [
"nova@0.1.0::compute",
"nova@0.1.0::monitor"
"nova::compute@0.1.0",
"nova::monitor@0.1.0"
]
}, {
"name": "controller",
"recipes": [
"cookbook@version::recipe"
"cookbook::recipe@2.1"
]
}
]

View File

@ -1,17 +1,17 @@
{
"name": "OpenStack",
"name": "Sample release",
"version": "1.0.0",
"description": "The openstack default release",
"description": "Description for Release",
"roles": [{
"name": "compute",
"name": "role1",
"recipes": [
"nova@0.1.1::compute",
"nova@0.1.1::monitor"
"sample-cook::compute@0.3.0",
"sample-cook::monitor@0.3.0"
]
},{
"name": "controller",
"name": "role2",
"recipes": [
"other_cookbook@2.4.2::api"
"sample-cook::default@0.3.0"
]
}
]