prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) pro<|fim_middle|> =50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
tein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: ver<|fim_middle|> name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
bose_name = "สารอาหาร" verbose_
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาห<|fim_middle|> =50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
าร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) creat<|fim_middle|> ate = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
ed_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_d
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ<|fim_middle|> ิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
่มหมวดหมู่วัตถุด
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'in<|fim_middle|> ate = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
gredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_d
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = mode<|fim_middle|> utrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
ls.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) n
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatibl<|fim_middle|> nt(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
e class Ingredie
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name<|fim_middle|> utrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
= models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) n
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, <|fim_middle|> , on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100,<|fim_middle|> description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
unique=True)
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.Cha<|fim_middle|> , on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
rField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, <|fim_middle|> db_table = 'menu' <|fim▁end|>
blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta:
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.C<|fim_middle|> ht = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
ASCADE) weig
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(m<|fim_middle|> db_table = 'menu' <|fim▁end|>
ax_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta:
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim_middle|> <|fim▁end|>
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim_middle|> <|fim▁end|>
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def <|fim_middle|>(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
__str__
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def <|fim_middle|>(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
__str__
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): ret<|fim_middle|>f.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
urn sel
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) <|fim_middle|>eta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
class M
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" ver<|fim_middle|>me_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
bose_na
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @pyt<|fim_middle|>nicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
hon_2_u
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.Ch<|fim_middle|>(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
arField
<|file_name|>models.py<|end_file_name|><|fim▁begin|>##-*-coding: utf-8 -*- from django.db import models from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Usage(models.Model): ip = models.CharField(max_length=50) method = models.CharField(max_length=3) path = models.CharField(max_length=100) params = models.CharField(max_length=255) def __str__(self): return self.ip @python_2_unicode_compatible class Element(models.Model): name = models.CharField(max_length=10) code = models.CharField(max_length=10) def __str__(self): return self.name class Meta: verbose_name = "ธาตุ" verbose_name_plural = "ธาตุต่างๆ" db_table = 'element' @python_2_unicode_compatible class Disease(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, null=True) is_congenital = models.BooleanField(default=False) created_by = models.CharField(max_length=50, null=True) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "เชื้อโรค" verbose_name_plural = "กลุ่มเชื้อโรค" db_table = 'disease' class Nutrient(models.Model): water = models.DecimalField(max_digits=14, decimal_places=4) protein = models.DecimalField(max_digits=14, decimal_places=4) fat = models.DecimalField(max_digits=14, decimal_places=4) carbohydrate = models.DecimalField(max_digits=14, decimal_places=4) dietary_fiber = models.DecimalField(max_digits=14, decimal_places=4) ash = models.DecimalField(max_digits=14, decimal_places=4) calcium = models.DecimalField(max_digits=14, decimal_places=4) phosphorus = models.DecimalField(max_digits=14, decimal_places=4) iron = models.DecimalField(max_digits=14, decimal_places=4) retinol = models.DecimalField(max_digits=14, decimal_places=4) beta_carotene = models.DecimalField(max_digits=14, decimal_places=4) vitamin_a = models.DecimalField(max_digits=14, decimal_places=4) vitamin_e = models.DecimalField(max_digits=14, decimal_places=4) thiamin = models.DecimalField(max_digits=14, decimal_places=4) riboflavin = models.DecimalField(max_digits=14, decimal_places=4) niacin = models.DecimalField(max_digits=14, decimal_places=4) vitamin_c = models.DecimalField(max_digits=14, decimal_places=4) def __str__(self): return 'id: ' + str(self._get_pk_val()) class Meta: verbose_name = "สารอาหาร" verbose_name_plural = "กลุ่มสารอาหาร" db_table = 'nutrient' @python_2_unicode_compatible class IngredientCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่วัตถุดิบ" verbose_name_plural = "กลุ่มหมวดหมู่วัตถุดิบ" db_table = 'ingredient_type' @python_2_unicode_compatible class FoodCategory(models.Model): name = models.CharField(max_length=50, unique=True) created_by = models.CharField(max_length=50) created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name = "หมวดหมู่อาหาร" verbose_name_plural = "กลุ่มหมวดหมู่อาหาร" db_table = 'food_type' @python_2_unicode_compatible class Ingredient(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True) calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) element = models.ForeignKey(Element, on_delete=models.SET_NULL, blank=True, null=True) category = models.ManyToManyField(IngredientCategory, blank=True) healing = models.ManyToManyField(Disease, related_name="healing", blank=True) affect = models.ManyToManyField(Disease, related_name="affect", blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "วัตถุดิบ" verbose_name_plural = "กลุ่มวัตถุดิบ" db_table = 'ingredient' @python_2_unicode_compatible class Food(models.Model): name = models.CharField(max_length=100, unique=True) description = models.CharField(max_length=255, blank=True, null=True, default="") calories = models.IntegerField(default=0) nutrient = models.ForeignKey(Nutrient, on_delete=models.SET_NULL, blank=True, null=True) ingredients = models.ManyToManyField(Ingredient, through='Menu') category = models.ManyToManyField(FoodCategory) created_by = models.CharField(max_length=50, default="") created_date = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True, null=True) last_modified_by = models.CharField(max_length=30, null=True, blank=True) code = models.IntegerField(default=0) def __str__(self): return self.name class Meta: verbose_name = "อาหาร" verbose_name_plural = "กลุ่มอาหาร" db_table = 'food' class Menu(models.Model): food = models.ForeignKey(Food, on_delete=models.CASCADE) ingredient = models.ForeignKey(Ingredi<|fim_middle|>_delete=models.CASCADE) weight = models.DecimalField(max_digits=14, decimal_places=4) name = models.CharField(max_length=100, blank=True, default="") class Meta: db_table = 'menu' <|fim▁end|>
ent, on
<|file_name|>config.py<|end_file_name|><|fim▁begin|>from network import WLAN ############################################################################### # Settings for WLAN STA mode ############################################################################### WLAN_MODE = 'off' #WLAN_SSID = '' #WLAN_AUTH = (WLAN.WPA2,'') ############################################################################### # LoRaWAN Configuration ############################################################################### # May be either 'otaa', 'abp', or 'off' LORA_MODE = 'otaa' # Settings for mode 'otaa' LORA_OTAA_EUI = '70B3D57EF0001ED4' LORA_OTAA_KEY = None # See README.md for instructions!<|fim▁hole|>#LORA_ABP_NETKEY = '' #LORA_ABP_APPKEY = '' # Interval between measures transmitted to TTN. # Measured airtime of transmission is 56.6 ms, fair use policy limits us to # 30 seconds per day (= roughly 500 messages). We default to a 180 second # interval (=480 messages / day). LORA_SEND_RATE = 180 ############################################################################### # GNSS Configuration ############################################################################### GNSS_UART_PORT = 1 GNSS_UART_BAUD = 9600 GNSS_ENABLE_PIN = 'P8'<|fim▁end|>
# Settings for mode 'abp' #LORA_ABP_DEVADDR = ''
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader;<|fim▁hole|># short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0<|fim▁end|>
# char modOrderPayload;
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): <|fim_middle|> #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1]
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): <|fim_middle|> def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): <|fim_middle|> def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength)
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): <|fim_middle|> #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1]
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): <|fim_middle|> #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): <|fim_middle|> def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): <|fim_middle|> def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam)
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): <|fim_middle|> #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
pass #print "Successfully executed command %d" % self.cmdID
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): <|fim_middle|> #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7]
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): <|fim_middle|> def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): <|fim_middle|> def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType)
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): <|fim_middle|> #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7]
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): <|fim_middle|> <|fim▁end|>
totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): <|fim_middle|> def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): <|fim_middle|> def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0)
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): <|fim_middle|> def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7]
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): <|fim_middle|> <|fim▁end|>
self.totalBitsReceived = 0 self.totalBitErrors = 0
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def <|fim_middle|>(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
__init__
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def <|fim_middle|>(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
prepToSend
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def <|fim_middle|>(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
updateFromNode
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def <|fim_middle|>(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
__init__
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def <|fim_middle|>(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
prepToSend
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def <|fim_middle|>(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
updateFromNode
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def <|fim_middle|>(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
__init__
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def <|fim_middle|>(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
prepToSend
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def <|fim_middle|>(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
updateFromNode
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def <|fim_middle|>(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
__init__
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def <|fim_middle|>(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
prepToSend
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def <|fim_middle|>(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def clearBitCounts(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
updateFromNode
<|file_name|>warpnet_experiment_structs.py<|end_file_name|><|fim▁begin|># WARPnet Client<->Server Architecture # WARPnet Parameter Definitions # # Author: Siddharth Gupta import struct, time from warpnet_common_params import * from warpnet_client_definitions import * from twisted.internet import reactor import binascii # Struct IDs STRUCTID_CONTROL = 0x13 STRUCTID_CONTROL_ACK = 0x14 STRUCTID_COMMAND = 0x17 STRUCTID_COMMAND_ACK = 0x18 STRUCTID_OBSERVE_BER = 0x24 STRUCTID_OBSERVE_BER_REQ = 0x25 STRUCTID_OBSERVE_PER = 0x26 STRUCTID_OBSERVE_PER_REQ = 0x27 # Command IDs COMMANDID_STARTTRIAL = 0x40 COMMANDID_STOPTRIAL = 0x41 COMMANDID_RESET_PER = 0x50 COMMANDID_ENABLE_BER_TESTING = 0x51 COMMANDID_DISABLE_BER_TESTING = 0x52 ######################## ## Struct Definitions ## ######################## # ControlStruct is a ClientStruct that stores some basic parameters to pass to the WARP board. The local variable can be accessed # globally by calling ControlStruct.txPower etc. The struct must also understand the conversion from integer values to binary # using the prepToSend function; it will be provided with the nodeID. # typedef struct { # char structID; # char nodeID; # char txPower; # char channel; # char modOrderHeader; # char modOrderPayload; # short reserved; # int pktGen_period; # int pktGen_length; # } warpnetControl; class ControlStruct(ClientStruct): txPower = -1 channel = -1 modOrderHeader = -1 modOrderPayload = -1 reserved = 0 packetGeneratorPeriod = 0 packetGeneratorLength = 0 def __init__(self): self.structID = STRUCTID_CONTROL self.txPower = 63 self.channel = 4 self.modOrderHeader = 0 self.modOrderPayload = 2 self.packetGeneratorPeriod = 0 self.packetGeneratorLength = 1300 self.expectedReturnStructID = STRUCTID_CONTROL_ACK def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!6BHII', self.structID, nodeID, self.txPower, self.channel, self.modOrderHeader, self.modOrderPayload, self.reserved, self.packetGeneratorPeriod, self.packetGeneratorLength) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!BBH', rawData[0:4]) #print "Control struct successfully applied at node %d" % dataTuple[1] #CommandStruct is used to send commands or requests to the WARP nodes # The cmdIDs are defined above # Matching C code definition: # typedef struct { # char structID; # char nodeID; # char cmdID; # char cmdParam; # } warpnetCommand; class CommandStruct(ClientStruct): cmdID = -1 cmdParam = -1 def __init__(self, cmdID, cmdParam): self.structID = STRUCTID_COMMAND self.expectedReturnStructID = STRUCTID_COMMAND_ACK self.cmdID = cmdID self.cmdParam = cmdParam def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.cmdID, self.cmdParam) def updateFromNode(self, rawData, pcapts): pass #print "Successfully executed command %d" % self.cmdID #ObservePERStruct collects packet error rate (PER) data from WARP nodes # Matching C code definition: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned char reqNum; # unsigned char reqType; # unsigned int numPkts_tx; # unsigned int numPkts_rx_good; # unsigned int numPkts_rx_goodHdrBadPyld; # unsigned int numPkts_rx_badHdr; # } warpnetObservePER; class ObservePERStruct(ClientStruct): numPkts_tx = -1 numPkts_rx_good = -1 numPkts_rx_goodHdrBadPyld = -1 numPkts_rx_badHdr = -1 reqNum = -1 reqType = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_PER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_PER self.numPkts_tx = 0 self.numPkts_rx_good = 0 self.numPkts_rx_goodHdrBadPyld = 0 self.numPkts_rx_badHdr = 0 self.reqNum = 0 self.reqType = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!4B', self.structID, nodeID, self.reqNum, self.reqType) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B 2B 4I', rawData[0:20]) self.reqNum = dataTuple[2] self.reqType = dataTuple[3] self.numPkts_tx = dataTuple[4] self.numPkts_rx_good = dataTuple[5] self.numPkts_rx_goodHdrBadPyld = dataTuple[6] self.numPkts_rx_badHdr = dataTuple[7] #Client struct for collecting BER updates from the ber_processor program # Matching C code struct: # typedef struct { # unsigned char structID; # unsigned char nodeID; # unsigned short sequenceNumber; # unsigned char nodeID_tx; # unsigned char nodeID_rx; # unsigned short mac_seqNum; # unsigned char mac_pktType; # unsigned char reserved0; # unsigned char reserved1; # unsigned char reserved2; # unsigned int bits_rx; # unsigned int bits_errors; # } warpnetObserveBER; class ObserveBERStruct(ClientStruct): totalBitsReceived = 0 totalBitErrors = 0 nodeID_tx = -1 nodeID_rx = -1 def __init__(self, logger=None): ClientStruct.__init__(self, logger) self.structID = STRUCTID_OBSERVE_BER_REQ self.expectedReturnStructID = STRUCTID_OBSERVE_BER self.totalBitsReceived = 0 self.totalBitErrors = 0 def prepToSend(self, nodeID): self.updateDone = False return struct.pack('!BBH', self.structID, nodeID, 0) def updateFromNode(self, rawData, pcapts): dataTuple = struct.unpack('!2B H 2B H 2I', rawData[0:16]) self.nodeID_tx = dataTuple[3] self.nodeID_rx = dataTuple[4] self.totalBitsReceived += dataTuple[6] self.totalBitErrors += dataTuple[7] def <|fim_middle|>(self): self.totalBitsReceived = 0 self.totalBitErrors = 0 <|fim▁end|>
clearBitCounts
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client):<|fim▁hole|> def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs)<|fim▁end|>
text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client)
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): <|fim_middle|> class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
""" This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume])
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): <|fim_middle|> def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup()
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): <|fim_middle|> def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid)
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty <|fim_middle|> def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs)
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): <|fim_middle|> def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): <|fim_middle|> def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id)
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice <|fim_middle|> def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF')
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice <|fim_middle|> def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available')
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): <|fim_middle|> def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server])
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): <|fim_middle|> def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
return ssh_client.exec_command('cat /tmp/text')
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): <|fim_middle|> def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client)
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): <|fim_middle|> def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id'])
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): <|fim_middle|> @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
actual = self._get_content(ssh_client) self.assertEqual(expected, actual)
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): <|fim_middle|> class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume])
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): <|fim_middle|> <|fim▁end|>
def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs)
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): <|fim_middle|> <|fim▁end|>
bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs)
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: <|fim_middle|> super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
raise cls.skipException("Cinder volume snapshots are disabled")
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: <|fim_middle|> else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip']
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: <|fim_middle|> return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0]
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def <|fim_middle|>(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
resource_setup
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def <|fim_middle|>(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_create_volume_from_image
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def <|fim_middle|>(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_boot_instance_from_volume
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def <|fim_middle|>(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_create_snapshot_from_volume
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def <|fim_middle|>(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_create_volume_from_snapshot
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def <|fim_middle|>(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_stop_instances
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def <|fim_middle|>(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_detach_volumes
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def <|fim_middle|>(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_ssh_to_server
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def <|fim_middle|>(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_get_content
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def <|fim_middle|>(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_write_text
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def <|fim_middle|>(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_delete_server
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def <|fim_middle|>(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_check_content_of_written_file
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def <|fim_middle|>(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def _boot_instance_from_volume(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
test_volume_boot_pattern
<|file_name|>test_volume_boot_pattern.py<|end_file_name|><|fim▁begin|># Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from tempest.common.utils import data_utils from tempest import config from tempest.openstack.common import log from tempest.scenario import manager from tempest import test CONF = config.CONF LOG = log.getLogger(__name__) class TestVolumeBootPattern(manager.ScenarioTest): """ This test case attempts to reproduce the following steps: * Create in Cinder some bootable volume importing a Glance image * Boot an instance from the bootable volume * Write content to the volume * Delete an instance and Boot a new instance from the volume * Check written content in the instance * Create a volume snapshot while the instance is running * Boot an additional instance from the new snapshot based volume * Check written content in the instance booted from snapshot """ @classmethod def resource_setup(cls): if not CONF.volume_feature_enabled.snapshot: raise cls.skipException("Cinder volume snapshots are disabled") super(TestVolumeBootPattern, cls).resource_setup() def _create_volume_from_image(self): img_uuid = CONF.compute.image_ref vol_name = data_utils.rand_name('volume-origin') return self.create_volume(name=vol_name, imageRef=img_uuid) def _boot_instance_from_volume(self, vol_id, keypair): # NOTE(gfidente): the syntax for block_device_mapping is # dev_name=id:type:size:delete_on_terminate # where type needs to be "snap" if the server is booted # from a snapshot, size instead can be safely left empty bd_map = [{ 'device_name': 'vda', 'volume_id': vol_id, 'delete_on_termination': '0'}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping': bd_map, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) def _create_snapshot_from_volume(self, vol_id): snap_name = data_utils.rand_name('snapshot') snap = self.snapshots_client.create_snapshot( volume_id=vol_id, force=True, display_name=snap_name) self.addCleanup_with_wait( waiter_callable=self.snapshots_client.wait_for_resource_deletion, thing_id=snap['id'], thing_id_param='id', cleanup_callable=self.delete_wrapper, cleanup_args=[self.snapshots_client.delete_snapshot, snap['id']]) self.snapshots_client.wait_for_snapshot_status(snap['id'], 'available') self.assertEqual(snap_name, snap['display_name']) return snap def _create_volume_from_snapshot(self, snap_id): vol_name = data_utils.rand_name('volume') return self.create_volume(name=vol_name, snapshot_id=snap_id) def _stop_instances(self, instances): # NOTE(gfidente): two loops so we do not wait for the status twice for i in instances: self.servers_client.stop(i['id']) for i in instances: self.servers_client.wait_for_server_status(i['id'], 'SHUTOFF') def _detach_volumes(self, volumes): # NOTE(gfidente): two loops so we do not wait for the status twice for v in volumes: self.volumes_client.detach_volume(v['id']) for v in volumes: self.volumes_client.wait_for_volume_status(v['id'], 'available') def _ssh_to_server(self, server, keypair): if CONF.compute.use_floatingip_for_ssh: _, floating_ip = self.floating_ips_client.create_floating_ip() self.addCleanup(self.delete_wrapper, self.floating_ips_client.delete_floating_ip, floating_ip['id']) self.floating_ips_client.associate_floating_ip_to_server( floating_ip['ip'], server['id']) ip = floating_ip['ip'] else: network_name_for_ssh = CONF.compute.network_for_ssh ip = server.networks[network_name_for_ssh][0] return self.get_remote_client(ip, private_key=keypair['private_key'], log_console_of_servers=[server]) def _get_content(self, ssh_client): return ssh_client.exec_command('cat /tmp/text') def _write_text(self, ssh_client): text = data_utils.rand_name('text-') ssh_client.exec_command('echo "%s" > /tmp/text; sync' % (text)) return self._get_content(ssh_client) def _delete_server(self, server): self.servers_client.delete_server(server['id']) self.servers_client.wait_for_server_termination(server['id']) def _check_content_of_written_file(self, ssh_client, expected): actual = self._get_content(ssh_client) self.assertEqual(expected, actual) @test.skip_because(bug='1373513') @test.services('compute', 'volume', 'image') def test_volume_boot_pattern(self): keypair = self.create_keypair() self.security_group = self._create_security_group() # create an instance from volume volume_origin = self._create_volume_from_image() instance_1st = self._boot_instance_from_volume(volume_origin['id'], keypair) # write content to volume on instance ssh_client_for_instance_1st = self._ssh_to_server(instance_1st, keypair) text = self._write_text(ssh_client_for_instance_1st) # delete instance self._delete_server(instance_1st) # create a 2nd instance from volume instance_2nd = self._boot_instance_from_volume(volume_origin['id'], keypair) # check the content of written file ssh_client_for_instance_2nd = self._ssh_to_server(instance_2nd, keypair) self._check_content_of_written_file(ssh_client_for_instance_2nd, text) # snapshot a volume snapshot = self._create_snapshot_from_volume(volume_origin['id']) # create a 3rd instance from snapshot volume = self._create_volume_from_snapshot(snapshot['id']) instance_from_snapshot = self._boot_instance_from_volume(volume['id'], keypair) # check the content of written file ssh_client = self._ssh_to_server(instance_from_snapshot, keypair) self._check_content_of_written_file(ssh_client, text) # NOTE(gfidente): ensure resources are in clean state for # deletion operations to succeed self._stop_instances([instance_2nd, instance_from_snapshot]) self._detach_volumes([volume_origin, volume]) class TestVolumeBootPatternV2(TestVolumeBootPattern): def <|fim_middle|>(self, vol_id, keypair): bdms = [{'uuid': vol_id, 'source_type': 'volume', 'destination_type': 'volume', 'boot_index': 0, 'delete_on_termination': False}] self.security_group = self._create_security_group() security_groups = [{'name': self.security_group['name']}] create_kwargs = { 'block_device_mapping_v2': bdms, 'key_name': keypair['name'], 'security_groups': security_groups } return self.create_server(image='', create_kwargs=create_kwargs) <|fim▁end|>
_boot_instance_from_volume
<|file_name|>test_chart_title01.py<|end_file_name|><|fim▁begin|>############################################################################### #<|fim▁hole|># from ..excel_comparsion_test import ExcelComparisonTest from ...workbook import Workbook class TestCompareXLSXFiles(ExcelComparisonTest): """ Test file created by XlsxWriter against a file created by Excel. """ def setUp(self): self.maxDiff = None filename = 'chart_title01.xlsx' test_dir = 'xlsxwriter/test/comparison/' self.got_filename = test_dir + '_test_' + filename self.exp_filename = test_dir + 'xlsx_files/' + filename self.ignore_files = [] self.ignore_elements = {} def test_create_file(self): """Test the creation of an XlsxWriter file with default title.""" workbook = Workbook(self.got_filename) worksheet = workbook.add_worksheet() chart = workbook.add_chart({'type': 'column'}) chart.axis_ids = [46165376, 54462720] data = [ [1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], ] worksheet.write_column('A1', data[0]) worksheet.write_column('B1', data[1]) worksheet.write_column('C1', data[2]) chart.add_series({'values': '=Sheet1!$A$1:$A$5', 'name': 'Foo'}) chart.set_title({'none': True}) worksheet.insert_chart('E9', chart) workbook.close() self.assertExcelEqual()<|fim▁end|>
# Tests for XlsxWriter. # # Copyright (c), 2013-2016, John McNamara, [email protected]
<|file_name|>test_chart_title01.py<|end_file_name|><|fim▁begin|>############################################################################### # # Tests for XlsxWriter. # # Copyright (c), 2013-2016, John McNamara, [email protected] # from ..excel_comparsion_test import ExcelComparisonTest from ...workbook import Workbook class TestCompareXLSXFiles(ExcelComparisonTest): <|fim_middle|> <|fim▁end|>
""" Test file created by XlsxWriter against a file created by Excel. """ def setUp(self): self.maxDiff = None filename = 'chart_title01.xlsx' test_dir = 'xlsxwriter/test/comparison/' self.got_filename = test_dir + '_test_' + filename self.exp_filename = test_dir + 'xlsx_files/' + filename self.ignore_files = [] self.ignore_elements = {} def test_create_file(self): """Test the creation of an XlsxWriter file with default title.""" workbook = Workbook(self.got_filename) worksheet = workbook.add_worksheet() chart = workbook.add_chart({'type': 'column'}) chart.axis_ids = [46165376, 54462720] data = [ [1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], ] worksheet.write_column('A1', data[0]) worksheet.write_column('B1', data[1]) worksheet.write_column('C1', data[2]) chart.add_series({'values': '=Sheet1!$A$1:$A$5', 'name': 'Foo'}) chart.set_title({'none': True}) worksheet.insert_chart('E9', chart) workbook.close() self.assertExcelEqual()
<|file_name|>test_chart_title01.py<|end_file_name|><|fim▁begin|>############################################################################### # # Tests for XlsxWriter. # # Copyright (c), 2013-2016, John McNamara, [email protected] # from ..excel_comparsion_test import ExcelComparisonTest from ...workbook import Workbook class TestCompareXLSXFiles(ExcelComparisonTest): """ Test file created by XlsxWriter against a file created by Excel. """ def setUp(self): <|fim_middle|> def test_create_file(self): """Test the creation of an XlsxWriter file with default title.""" workbook = Workbook(self.got_filename) worksheet = workbook.add_worksheet() chart = workbook.add_chart({'type': 'column'}) chart.axis_ids = [46165376, 54462720] data = [ [1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], ] worksheet.write_column('A1', data[0]) worksheet.write_column('B1', data[1]) worksheet.write_column('C1', data[2]) chart.add_series({'values': '=Sheet1!$A$1:$A$5', 'name': 'Foo'}) chart.set_title({'none': True}) worksheet.insert_chart('E9', chart) workbook.close() self.assertExcelEqual() <|fim▁end|>
self.maxDiff = None filename = 'chart_title01.xlsx' test_dir = 'xlsxwriter/test/comparison/' self.got_filename = test_dir + '_test_' + filename self.exp_filename = test_dir + 'xlsx_files/' + filename self.ignore_files = [] self.ignore_elements = {}
<|file_name|>test_chart_title01.py<|end_file_name|><|fim▁begin|>############################################################################### # # Tests for XlsxWriter. # # Copyright (c), 2013-2016, John McNamara, [email protected] # from ..excel_comparsion_test import ExcelComparisonTest from ...workbook import Workbook class TestCompareXLSXFiles(ExcelComparisonTest): """ Test file created by XlsxWriter against a file created by Excel. """ def setUp(self): self.maxDiff = None filename = 'chart_title01.xlsx' test_dir = 'xlsxwriter/test/comparison/' self.got_filename = test_dir + '_test_' + filename self.exp_filename = test_dir + 'xlsx_files/' + filename self.ignore_files = [] self.ignore_elements = {} def test_create_file(self): <|fim_middle|> <|fim▁end|>
"""Test the creation of an XlsxWriter file with default title.""" workbook = Workbook(self.got_filename) worksheet = workbook.add_worksheet() chart = workbook.add_chart({'type': 'column'}) chart.axis_ids = [46165376, 54462720] data = [ [1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], ] worksheet.write_column('A1', data[0]) worksheet.write_column('B1', data[1]) worksheet.write_column('C1', data[2]) chart.add_series({'values': '=Sheet1!$A$1:$A$5', 'name': 'Foo'}) chart.set_title({'none': True}) worksheet.insert_chart('E9', chart) workbook.close() self.assertExcelEqual()
<|file_name|>test_chart_title01.py<|end_file_name|><|fim▁begin|>############################################################################### # # Tests for XlsxWriter. # # Copyright (c), 2013-2016, John McNamara, [email protected] # from ..excel_comparsion_test import ExcelComparisonTest from ...workbook import Workbook class TestCompareXLSXFiles(ExcelComparisonTest): """ Test file created by XlsxWriter against a file created by Excel. """ def <|fim_middle|>(self): self.maxDiff = None filename = 'chart_title01.xlsx' test_dir = 'xlsxwriter/test/comparison/' self.got_filename = test_dir + '_test_' + filename self.exp_filename = test_dir + 'xlsx_files/' + filename self.ignore_files = [] self.ignore_elements = {} def test_create_file(self): """Test the creation of an XlsxWriter file with default title.""" workbook = Workbook(self.got_filename) worksheet = workbook.add_worksheet() chart = workbook.add_chart({'type': 'column'}) chart.axis_ids = [46165376, 54462720] data = [ [1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], ] worksheet.write_column('A1', data[0]) worksheet.write_column('B1', data[1]) worksheet.write_column('C1', data[2]) chart.add_series({'values': '=Sheet1!$A$1:$A$5', 'name': 'Foo'}) chart.set_title({'none': True}) worksheet.insert_chart('E9', chart) workbook.close() self.assertExcelEqual() <|fim▁end|>
setUp
<|file_name|>test_chart_title01.py<|end_file_name|><|fim▁begin|>############################################################################### # # Tests for XlsxWriter. # # Copyright (c), 2013-2016, John McNamara, [email protected] # from ..excel_comparsion_test import ExcelComparisonTest from ...workbook import Workbook class TestCompareXLSXFiles(ExcelComparisonTest): """ Test file created by XlsxWriter against a file created by Excel. """ def setUp(self): self.maxDiff = None filename = 'chart_title01.xlsx' test_dir = 'xlsxwriter/test/comparison/' self.got_filename = test_dir + '_test_' + filename self.exp_filename = test_dir + 'xlsx_files/' + filename self.ignore_files = [] self.ignore_elements = {} def <|fim_middle|>(self): """Test the creation of an XlsxWriter file with default title.""" workbook = Workbook(self.got_filename) worksheet = workbook.add_worksheet() chart = workbook.add_chart({'type': 'column'}) chart.axis_ids = [46165376, 54462720] data = [ [1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], ] worksheet.write_column('A1', data[0]) worksheet.write_column('B1', data[1]) worksheet.write_column('C1', data[2]) chart.add_series({'values': '=Sheet1!$A$1:$A$5', 'name': 'Foo'}) chart.set_title({'none': True}) worksheet.insert_chart('E9', chart) workbook.close() self.assertExcelEqual() <|fim▁end|>
test_create_file
<|file_name|>setup.py<|end_file_name|><|fim▁begin|>import os from setuptools import setup README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read() os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) setup( name='django-isegory', version='0.1', packages=['isegory'], include_package_data=True, license='AGPL', description='A simple Django app to declare the provenance of a dataset.',<|fim▁hole|> author='Javier de la Cueva', author_email='[email protected]', classifiers=[ 'Environment :: Web Environment', 'Framework :: Django', 'Intended Audience :: Developers', 'License :: OSI Approved :: AGPL', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', ], )<|fim▁end|>
long_description=README, url='http://github.com/jdelacueva/django-isegory/',
<|file_name|>factories.py<|end_file_name|><|fim▁begin|>import factory from .models import User USER_PASSWORD = "2fast2furious" class UserFactory(factory.DjangoModelFactory): name = "John Doe" email = factory.Sequence(lambda n: "john{}@example.com".format(n)) password = factory.PostGenerationMethodCall('set_password', USER_PASSWORD)<|fim▁hole|> class Meta: model = User<|fim▁end|>
gender = "male"
<|file_name|>factories.py<|end_file_name|><|fim▁begin|>import factory from .models import User USER_PASSWORD = "2fast2furious" class UserFactory(factory.DjangoModelFactory): <|fim_middle|> <|fim▁end|>
name = "John Doe" email = factory.Sequence(lambda n: "john{}@example.com".format(n)) password = factory.PostGenerationMethodCall('set_password', USER_PASSWORD) gender = "male" class Meta: model = User