/**
   * This method inserts a record into the rhnServerPackage mapping table to associate a given
   * Server with a particular Package. The web code doesn't actually create any of these records,
   * but this will be needed by the backend code.
   *
   * @param srvr Server to associate with the packages
   * @param p The package
   */
  public static void associateSystemToPackageWithArch(Server srvr, Package p) {
    try {
      WriteMode m =
          ModeFactory.getWriteMode("test_queries", "insert_into_rhnServerPackage_with_arch");

      Map<String, Long> params = new HashMap<String, Long>(4);
      params.put("server_id", srvr.getId());
      params.put("pn_id", p.getPackageName().getId());
      params.put("evr_id", p.getPackageEvr().getId());
      params.put("arch_id", p.getPackageArch().getId());

      m.executeUpdate(params);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  /**
   * Adds packages associated to the errata
   *
   * @param erratum erratum to be added
   * @param channel channel info
   * @throws SAXException
   */
  private void addErratumPkgList(Errata erratum, Channel channel) throws SAXException {
    handler.startElement("pkglist");

    SimpleAttributesImpl attr = new SimpleAttributesImpl();
    attr.addAttribute("short", channel.getLabel());
    handler.startElement("collection", attr);

    handler.addElementWithCharacters("name", channel.getName());

    Iterator iter = erratum.getPackages().iterator();

    while (iter.hasNext()) {
      Package pkg = (Package) iter.next();
      if (channel.getPackages().contains(pkg)) {
        long pkgId = pkg.getId();
        String epoch = pkg.getPackageEvr().getEpoch();
        if (epoch == null || epoch.length() == 0) {
          epoch = "0";
        }
        attr.clear();
        attr.addAttribute("name", sanitize(pkgId, pkg.getPackageName().getName()));
        attr.addAttribute("version", sanitize(pkgId, pkg.getPackageEvr().getVersion()));
        attr.addAttribute("release", sanitize(pkgId, pkg.getPackageEvr().getRelease()));
        attr.addAttribute("epoch", sanitize(pkgId, epoch));
        attr.addAttribute("arch", sanitize(pkgId, pkg.getPackageArch().getLabel()));
        attr.addAttribute("src", sanitize(pkgId, pkg.getSourceRpm().getName()));
        handler.startElement("package", attr);

        handler.addElementWithCharacters("filename", sanitize(pkgId, pkg.getFilename()));

        attr.clear();
        attr.addAttribute("type", sanitize(pkgId, pkg.getChecksum().getChecksumType().getLabel()));
        handler.startElement("sum", attr);
        handler.addCharacters(sanitize(pkgId, pkg.getChecksum().getChecksum()));
        handler.endElement("sum");

        handler.endElement("package");
      }
    }

    handler.endElement("collection");

    handler.endElement("pkglist");
  }
示例#3
0
  public void testAddPackage() throws Exception {
    Channel c = ChannelFactoryTest.createTestChannel(user);
    Package p = PackageTest.createTestPackage(user.getOrg());
    assertNotNull(c);
    assertEquals("channel-ia32", c.getChannelArch().getLabel());
    assertNotNull(p);
    assertEquals("noarch", p.getPackageArch().getLabel());

    try {
      c.addPackage(p);
    } catch (Exception e) {
      fail("noarch should be acceptible in an ia32 channel");
    }

    try {
      PackageArch pa = PackageFactory.lookupPackageArchByLabel("x86_64");
      assertNotNull(pa);
      p.setPackageArch(pa);
      c.addPackage(p);
      fail("x86_64 is not acceptible in an ia32 channel");
    } catch (Exception e) {
      // expected.
    }
  }
  // Check to make sure up2date is 2.9.0
  protected ValidatorError validateUp2dateVersion() {
    Server hostServer = getHostServer();
    List packages = PackageManager.systemPackageList(hostServer.getId(), null);
    if (packages != null) {
      log.debug("    packages.size() : " + packages.size());
    }
    // PackageListItem
    Iterator i = packages.iterator();
    String up2dateepoch = null;
    String up2dateversion = null;
    String up2daterelease = null;

    while (i.hasNext()) {
      PackageListItem pli = (PackageListItem) i.next();
      if (pli.getName().equals("yum-rhn-plugin")) {
        // found yum-rhn-plugin - returning
        return null;
      }
      if (pli.getName().equals("zypp-plugin-spacewalk")) {
        // found zypp-plugin-spacewalk - returning
        return null;
      }

      if (pli.getName().equals("up2date")) {
        log.debug("    found up2date ...");
        up2dateepoch = pli.getEpoch();
        up2dateversion = pli.getVersion();
        up2daterelease = pli.getRelease();

        log.debug("    e: " + up2dateepoch + " v: " + up2dateversion + " r : " + up2daterelease);
      }
    }

    if (up2dateepoch == null && up2dateversion == null && up2daterelease == null) {
      Object[] args = new Object[2];
      args[0] = hostServer.getId();
      args[1] = hostServer.getName();
      return new ValidatorError("kickstart.schedule.noup2date", args);
    }

    up2dateepoch = up2dateepoch == null ? "0" : up2dateepoch;
    up2dateversion = up2dateversion == null ? "0" : up2dateversion;
    up2daterelease = up2daterelease == null ? "0" : up2daterelease;

    int comp =
        PackageManager.verCmp(
            up2dateepoch, up2dateversion, up2daterelease, "0", UP2DATE_VERSION, "0");
    log.debug("    Got back comp from verCmp: " + comp);
    if (comp < 0) {
      Long packageId =
          PackageManager.getServerNeededUpdatePackageByName(hostServer.getId(), "up2date");
      if (packageId == null) {
        Object[] args = new Object[2];
        args[0] = UP2DATE_VERSION;
        args[1] = up2dateversion;
        return new ValidatorError("kickstart.schedule.noup2dateinchannel", args);
      }
      Package p = PackageFactory.lookupByIdAndUser(packageId, this.user);

      Map evrmap = new HashMap();
      evrmap.put("name_id", p.getPackageName().getId());
      evrmap.put("evr_id", p.getPackageEvr().getId());
      evrmap.put("arch_id", p.getPackageArch().getId());
      packagesToInstall.add(evrmap);
    } else {
      return null;
    }

    return null;
  }